0

I am using a DataGridView control in VB.Net and one of the columns is an unbound DataGridViewComboBoxColumn.

User can select one of 4 entries in the combo control. I need to determine what the combo box content/selection actually is. At present, I am unable to retrieve this content.

I have tried using the AddHandler combo.SelectionChangeCommitted() as advised on one of the other questions raised on this site, but neither param to this event (ByVal sender As System.Object, ByVal e As System.EventArgs) , will enable me to retrieve the actual row of the datagrid this combo control is on.

This is important because the row index of the grid is the key to the associated entry in my Dictionary object.

user6167266
  • 41
  • 11

1 Answers1

1

Based on what you said and your question title (the combo boxes are all selected):

  Dim ComboValue As String
  Dim ComboIndex As Integer
  Dim MyDict As New Dictionary(Of String, Integer)

   For i As Integer = 0 To My_DGV.SelectedCells.Count - 1

       ComboIndex = My_DGV.SelectedCells.Item(i).RowIndex
       ComboValue = My_DGV.Rows(ComboIndex).Cells("YourDatagridviewComboboxCell").Value
       MyDict.Add(ComboValue, ComboIndex)

   Next
LuckyLuke82
  • 586
  • 1
  • 18
  • 58
  • Thanks - that is helpful . ... however this event fires when the user moves to another grid row... the user will make all combo changes before activating the BOT. Once activated, when the refresh () routine is called- I would like to be able to work through the grid rows one at a time interrogating the value of each combo .... – user6167266 Jan 15 '17 at 11:46
  • @user6167266, you didn't mention this clearly. Take a look at my edit now, you need to do commit of the cell first. – LuckyLuke82 Jan 15 '17 at 11:50
  • I don't see how that is going to enable me to retrieve the cell value in the routine I have described...as I have mentioned the code is iterating through all rows in the DataGrid and retrieving the cell values..... – user6167266 Jan 15 '17 at 12:15
  • @user6167266, your question is not very precise. WHAT do you need as output - combobox cell value for all rows after they were commited + row index ? And what for, do you do separate procedures for each row value ?. Post some code in your question. – LuckyLuke82 Jan 15 '17 at 12:29
  • .. figured I had done that already... but for the record... ... the combo boxes are all selected.. user presses a button to activate the software... the refresh routine runs and iterates through all rows in the grid... it needs to retrieve each rows combo box value at this time only... NOT when the user makes the selection... Sure, the row index is simple enough in this instance.. but I cant seem to get the combobox cell value ... – user6167266 Jan 15 '17 at 13:47
  • @user6167266, take a look at edtied question now - is that what you need ? – LuckyLuke82 Jan 16 '17 at 08:25
  • Sure, thats fine. Thank you. – user6167266 Jan 16 '17 at 13:27