Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Value from a data grid

Status
Not open for further replies.

besto1a

Programmer
Aug 20, 2006
41
0
0
GB
Does any know how to get the value from a datagrid without accessing the dataset, ie what the value is at row 2 colunmn 5

Thanks
 
I believe it would be as follows.

DataGridView1.Rows.Item(1).Cells.Item(3).Value

The above would access row 1 and column 3
 
If you wanted to setup the code to find what row the user clicked you could use the following, I am sure you can modify it to locate more specifically:

Dim i As Integer = Me.datagridview.SelectedCells(0).RowIndex
 
I am trying to make this code populate a listbox with checkbox selected items from a gridview... however I am stuck on getting gridview item values to the listbox.
Code:
    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        'select the values of checkboxes from the Grid
        Dim i As Integer
        Dim li As ListItem
        Dim row As GridViewRow = GridView1.SelectedRow

 For i = 0 To GridView1.Rows.Count - 1
            If CType(GridView1.Rows(i).FindControl("chkSelection"), CheckBox).Checked() Then
      li = New ListItem(row.Cells(i).Text)
      ListBox1.Items.Add(li)
            End If
        Next

Any help here for a newbie would be great...

Thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top