Get value from gridview column
-
Wednesday, May 24, 2006 12:56 PM
How to get value (text) from gridview control in VB.
textbox.text = (value in column2 of selected row in gridview)
All Replies
-
Wednesday, May 24, 2006 1:14 PM
TextBox.Text = DataGridView1.Item(1, DataGridView1.SelectedRows(0).Index).Value
BTW, I suggest to don't use "TextBox" as a name for a textbox, this make the programmer confuse... -
Wednesday, May 24, 2006 1:16 PMHi there,
Perhaps something like:
ProductsDataGridView.SelectedRows(0).Cells(1).Value.ToString()
In the above ProductsDataGridView is the name of my DataGridView control. What the above line will do is get the first selected row (or the only selected row if the user only selects one at a time) and returns a string representation of the value in the second column of the row.
In your code, you'd prolly need to add some checks like making sure the user has actually selected a row.
Hope that helps a bit, but sorry if it doesn't
PS. Just saw the post by Moayad after I put my post up. I think it's better than mine
-
Thursday, May 25, 2006 6:43 AM
Thanks, this is very good idea, i using and folowed code
Dim
row As GridViewRow = GridView1.SelectedRow Dim key As String = GridView1.SelectedDataKey.Value.ToStringtxtDrzava.Text = row.Cells(1).Text
txtDrNaziv.Text = row.Cells(2).Text
-
Thursday, May 25, 2006 6:46 AMThanks, it's very interesting
-
Thursday, June 28, 2007 12:14 PM
I try it but i get one error..
Dim row As GridViewRow = GridView1.SelectedRow
Dim key As String = GridView1.SelectedDataKey.Value.ToString ( Object reference not set to an instance of an object. )
txtDrzava.Text = row.Cells(1).Text
txtDrNaziv.Text = row.Cells(2).Text
Somebody know why?
- Proposed As Answer by Winston Muller Wednesday, April 01, 2009 8:47 AM
-
Thursday, November 15, 2007 3:11 PM
Try this..equivalent to VB.net
string key = GridView1.DataKeys[e.RowIndex].Value.ToString();
-
Thursday, July 09, 2009 11:48 AMThanks a lot
-
Saturday, October 23, 2010 2:37 PM
TextBox.Text = DataGridView1.Item(1, DataGridView1.SelectedRows(0).Index).Value
BTW, I suggest to don't use "TextBox" as a name for a textbox, this make the programmer confuse...
Excellent -
Wednesday, October 12, 2011 9:45 AM
For Each row As DataGridViewRow In datadv.SelectedRows
txtbox1.Text = row.Cells("Slno").Value.ToString()
txtbox2.Text = row.Cells("Name").Value.ToString()
Nexttry this...
-
Thursday, October 13, 2011 8:12 AM
Hi, I'm coding C# script in Test Complete tool. I get the value from grid by function:
function FindRowByCellValue (Grid, ChildView, ColName, SoughtValue){
var Val, i;
if (ChildView == null)
ChildView = Grid;
Val = VarToStr (SoughtValue);
// Iterate through grid rows
for (i = 0; i < ChildView["wRowCount"]; i++)
// Compare the cell value with the specified value
if (VarToStr(ChildView["wValue"](i,ColName)) == Val)
ShowMessage("Value at row " + i);
ShowMessage("Value not found in any row!");
}
Have anyway to get all items in grid?
Thanks.

