问题描述
我有一个字符串数组,想用 windows 窗体上的一些文本框绑定到这个数组
I have a string array and want to bind to this array with some text boxes on a windows form
数组有固定长度的 5 个元素,在我的表单上我有 5 个文本框,我想将 textbox1 绑定到字符串数组的元素 1,将 textbox2 绑定到字符串数组的元素 2,依此类推.
The array has a fixed length of 5 elements, on my form I have 5 text boxes, I want to bind textbox1 to element 1 of the string array, textbox2 to element 2 of the string array and so on.
我该怎么做?甚至有可能吗?
How do I go about that? Is it even possible?
txtMonth1.DataBindings.Add(New Binding("Text", bsReport, "LabelName(0)", True))txtMonth2.DataBindings.Add(New Binding("Text", bsReport, "LabelName(1)", True))等等等
txtMonth1.DataBindings.Add(New Binding("Text", bsReport, "LabelName(0)", True))txtMonth2.DataBindings.Add(New Binding("Text", bsReport, "LabelName(1)", True))etcetc
干杯
推荐答案
是的,您可以将 TextBoxes
绑定到数组的各个元素.
Yes, you can bind TextBoxes
to individual elements of an array.
类似于以下内容:
txtMonth1.DataBindings.Add(New Binding("Text", bsReport[0], "LabelName(0)", True))
txtMonth2.DataBindings.Add(New Binding("Text", bsReport[1], "LabelName(1)", True))
这篇关于Winforms 数据绑定到数组中的元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!