开发者

using Bindinglist as bind for Textbox

开发者 https://www.devze.com 2023-01-15 06:56 出处:网络
I have a bindinglist. i am us开发者_如何学编程ing a textbox to show its items WithEvents xBind As New BindingList(Of Emp)

I have a bindinglist. i am us开发者_如何学编程ing a textbox to show its items

WithEvents xBind As New BindingList(Of Emp)

I added items this way

xBind.Add(New emp("alpha0", "B"))
xBind.Add(New emp("alpha1", "B"))
xBind.Add(New emp("alpha2", "B"))
xBind.Add(New emp("alpha3", "B"))

I am binding the first property to a textbox

TextBox1.DataBindings.Add("text", xBind, "eName")

It shows "alpha0" in the form which is first item in the xbind Now how do I display the second item in textbox1 when i click "MoveNext" button ?


I happened upon this while seeking a solution to a similar question. For anyone else who may come across this, my solution was to use a BindingSource.

Dim bsXBind As New BindingSource
...
bsXBind.DataSource = xBind
TextBox1.DataBindings.Add("Text", bsXBind, "eName")

To move to another record, change BindingSource.Position:

Private Sub NextXRecord()
    If bsXBind.Position < bsXBind.Count - 1 Then
        bsXBind.Position += 1
    End If
End Sub


I think you need a listbox or grid instead of a textbox, which only shows one value at a time.

0

精彩评论

暂无评论...
验证码 换一张
取 消