user525862
user525862

Reputation: 1

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.

Upvotes: 0

Views: 2317

Answers (3)

Jay
Jay

Reputation: 6017

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.

Upvotes: 1

IAbstract
IAbstract

Reputation: 19881

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.

Upvotes: 0

Ali Tarhini
Ali Tarhini

Reputation: 5358

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)

Upvotes: 1

Related Questions