datagridview / cells and rows

hi,

i need help, how can i get the value from a particular dgvcell if i'll select the entire dgvrow and how to auto-select a row




Answer this question

datagridview / cells and rows

  • Metall

    oh yeah. . .

    if your grid is bound to a binding source which is inturn bound to an IList, at any given time, BindingSource.Position will return the index of the currently selected item in your IList

    BindingSource.Current gives the actual selected item though you will have to cast it to the particular item. if your ilist is a Dataable, you will need to cast it to a DataTableRow



  • Andy K Smith

    it may be a DataRowView.

    not in a place i can check, but put a breakpoint there and inspect it using a watch. it will tell you what class it is.



  • ChicagoDave

    Hi, am trying to do the same thing, where im pulling some info from within a record. am using the binding source.current to get the obj. but im getting stuck on how to cast to a dataTableRow.

    Can anyone help me

    Thanks.


  • Luke Waters

    thats brilliant got it working now.

    super fast reply.

    Thanks!


  • Chippen

    thanks I got it..

  • MartinParé

    newTempProductRow = (product_dbDataSetComp.Tbl_HW_ProductsRow) this.tblHwCompProductsBindingSource.Current;

    something like that im a bit lost at the min....


  • Primo109

    mark the answer



  • Chaz Clover

    Look at BindingSource.position

  • Balasaheb

    Try:

    newTempProductRow =
    (
    this.tblHwCompProductsBindingSource.Current as DataRowView).Row
    as product_dbDataSetComp.Tbl_HW_ProductsRow;

    Might want to try checking for nulls

    if ( !this.tblHwCompProductsBindingSource.Current == null )
    newTempProductRow =
    (
    this.tblHwCompProductsBindingSource.Current as DataRowView).Row
    as product_dbDataSetComp.Tbl_HW_ProductsRow;



  • datagridview / cells and rows