Winforms 数据绑定到数组中的元素 [英] Winforms Databinding to element in array

查看:32
本文介绍了Winforms 数据绑定到数组中的元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个字符串数组,想用 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)) etc etc

干杯

推荐答案

是的,您可以将 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 数据绑定到数组中的元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆