How To Get Grid Current Cell Text

How can I get the DataGridView cell contents in the Current Row Column 1

I tried this but it doesnt work

TextBox1.Text = CType(ProductsDataGridView.CurrentCell.RowIndex, String) & CType(ProductsDataGridView.Columns(1), String)


Answer this question

How To Get Grid Current Cell Text

  • Dave DeJonge

    What's bound to your datagrid   If the grid is bound directly to a table then this code works.  If you're bound to some other datasource you may have to adjust the type that bmb.current gets converted to.
  • YuvalO

    I get an error at DataRowView
    Do you think you could take another look -- Thanks

  • WillfinDavid

    Wouldn't ...

    ProductsDataGridView.Rows[ProductsDataGridView.CurrentCell.RowIndex].Cells[0].Value;

    work

  • Vitoto

    One option would be:


    Dim bmb As BindingManagerBase = Me.BindingContext(ProductsDataGridView.DataSource, ProductsDataGridView.DataMember)

    TextBox1.Text = CType(bmb.Current, DataRowView).Item(0)


    Item(0) is the first column as the column numbering is 0 based.  If you wanted the value at the second column you would use Item(1).

  • How To Get Grid Current Cell Text