Detected Selected Item in datagridview

compguru910

Well-known member
Joined
Nov 25, 2009
Messages
47
Programming Experience
3-5
Im running into an issue. Im using a datagridview to display repair orders open in a shop. There is a dates form that I need to load and display different dates. Well I can get that to work, and it works fine. But if I click the button that loads the dates form without selecting an item in the datagridview, then I get an error when trying to pass a variable from the datagridview to the new form (because there is no item selected). What im trying to do is detect if an item in the dgv is selected before it trys to pass the variable. Heres what I go, but it doesnt work

VB.NET:
        If dgvMain.SelectedCells.Count = 0 Then
            MsgBox("Please select an RO to continue")
        Else
            Using fDates As New frmDates
                fDates.intROID = dgvMain.Item(0, dgvMain.CurrentRow.Index).Value
                fDates.ShowDialog()
            End Using
        End If

I have multiselection turned off as well. So the most that should be selected is 1. But, that doesnt work. Another thing I would like to know, is how to programmticaly set the selection at run time. Thanks in advanced
 
Back
Top