Fill Text from Datagridview to TextBox

xswzaq

Well-known member
Joined
Jul 9, 2007
Messages
61
Programming Experience
Beginner
Hello All, I have a question to ask, Is there a way to get Text in Column1 from Datagridview to Textbox1? I appriciate any reply. Thank you very much.
 
Sure, this is untested, but it looks like this :

VB.NET:
txt_Current.Text = DirectCast(grid_Items.Rows(0).Cells("ColumnNameOrIndex").Value, String)

You must specify the row by index first (or use grid_Items.CurrentRow to get the currently active row), then the cell by using the column's name or index. This code must be surrounded by proper validation in case the cell's value is DBNULL as BDNULL cannot be cast to String.
 
Sure, this is untested, but it looks like this :

VB.NET:
txt_Current.Text = DirectCast(grid_Items.Rows(0).Cells("ColumnNameOrIndex").Value, String)

You must specify the row by index first (or use grid_Items.CurrentRow to get the currently active row), then the cell by using the column's name or index. This code must be surrounded by proper validation in case the cell's value is DBNULL as BDNULL cannot be cast to String.

Given that the DataGridView would probably be bound to a datasource such as a DataTable, you would simply bind the textbox to the required column ,through the same bindingsource
 
Back
Top