Get Selected Row in DataGridView not working VB.Net -
i have pretty standard datagridview , have used
.selectionmode = datagridviewselectionmode.fullrowselect .multiselect = false
in order ensure entire row selected.
situation : need obtain selected row in order load data in row screen "modify" data. using following selected row.
private sub datagridview2_cellcontentclick(sender object, e datagridviewcelleventargs) handles datagridview2.cellcontentclick try if e.rowindex >= 0 dim row datagridviewrow row = me.datagridview2.rows(e.rowindex) globalvariables.selectedlineitemrowno = e.rowindex ' or row msgbox("globalvariables.selectedlineitemrowno ---> " & globalvariables.selectedlineitemrowno) 'textboxtst.text = row.cells("description").value.tostring end if catch ex exception msgbox(ex.message) end try end sub
question : problem of time when 1 clicks on data within dgv code above run , sets e.rowindex - when hit white space on row nothing happens , results in problem of using previous row selected, in fact wrong row.?
any ideas appreciated. in advance
i think looking datagridview cellclick instead of cellcontentclick. cellcontentclick not fire when white space around cell content clicked.
private sub datagridview2_cellclick(byval sender object, byval e system.windows.forms.datagridviewcelleventargs) handles datagridview2.cellclick try if e.rowindex >= 0 dim row datagridviewrow row = me.datagridview2.rows(e.rowindex) globalvariables.selectedlineitemrowno = e.rowindex ' or row msgbox("globalvariables.selectedlineitemrowno ---> " & globalvariables.selectedlineitemrowno) 'textboxtst.text = row.cells("description").value.tostring end if catch ex exception msgbox(ex.message) end try end sub
Comments
Post a Comment