开发者

Populate text boxes in VB.net

I am retrieving a single row (using a method) from a table, I开发者_开发技巧 want to populate each column from this row into text boxes. How can this be done in VB.net.

Thanks for the help.


for i = 0 to Table.Rows.Count -1
    dim row as DataRow = Table.Rows(i)
    dim txt as new textbox
    txt.Text = row(i)
    panel1.controls.add(txt)
Next

where panel1 is a FlowLayoutPanel(it automatically positions the textboxes for you)


If I read what you said correctly, you want a text box for each column in the datarow. So you want something like this:

    For i As Integer = 0 To row.ItemArray.Length - 1
        Dim txtBox As New TextBox
        txtBox.Text = row.Item(i).ToString
        Form1.Controls.add(txtBox)
    Next

Row being replaced with the method that returns your row, and whatever control you are adding the text box to in place of the Form1.


You can do it several ways...but I think DataBinding may be the most generally accepted method. The problem with DataBinding is that you cannot bind to a DataRow. You must bind to the DataRow's Table.

myTextBox.DataBindings.Add("Text", myDataTable, "ColumnName");

Check out more at MSDN if you wish.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜