I have a bound DataGridView with a bound ComboBoxColumn in it. This CombobBoxColumn is a list of delivery routes for our company. I want to restrict this ComboBoxColumn to not allow duplicate routes to be selected in more than one row. I am having a tough time in figuring a way to do this.
I am willing to consider any suggestions...be they from a validating standpoint, a datasource change standpoint...anything you might have to offer. it can even be as simple of a message to the user saying the selected route is already assigned.
I have tried a few things, such as using the below check and EditingControlShowing event examples I found with web searches.
Example:
Thanks for any input you can offer....
=======================================
People think it must be fun to be a super genius, but they don't realize how hard it is to put up with all the idiots in the world. (Calvin from Calvin And Hobbs)
Robert L. Johnson III
CCNA, CCDA, MCSA, CNA, Net+, A+, CHDP
VB.NET Programmer
Code:
Driver Assigned Route
John Smith 101
Jacob Jones 102
Mark Summers 103
Gary Love 103 *** I don't want this to be able to happen ***
Julias Harvey 104
I am willing to consider any suggestions...be they from a validating standpoint, a datasource change standpoint...anything you might have to offer. it can even be as simple of a message to the user saying the selected route is already assigned.
I have tried a few things, such as using the below check and EditingControlShowing event examples I found with web searches.
Example:
Code:
Private Sub NamesAndNumbersDataGridView_CellValidating(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellValidatingEventArgs) Handles NamesAndNumbersDataGridView.CellValidating
If e.ColumnIndex = 13 AndAlso Me.NamesAndNumbersDataGridView.CurrentCell.FormattedValue.ToString.Length > 0 Then
Dim UsedRoutes(999) As Int32
Dim i As Int32 = -1
For j As Int32 = 0 To Me.NamesAndNumbersDataGridView.Rows.Count - 1
i += 1
If Me.NamesAndNumbersDataGridView.Rows(j).Cells(13).FormattedValue.ToString.Trim.Length > 0 Then
UsedRoutes(i) = Convert.ToInt32(Me.NamesAndNumbersDataGridView.Rows(j).Cells(13).FormattedValue.ToString)
End If
Next
If Array.IndexOf(UsedRoutes, Convert.ToInt32(Me.NamesAndNumbersDataGridView.CurrentCell.FormattedValue.ToString)) > 0 Then
MessageBox.Show("Route " & Me.NamesAndNumbersDataGridView.CurrentCell.FormattedValue.ToString & " is already in use.")
End If
End If
End Sub
Thanks for any input you can offer....
=======================================
People think it must be fun to be a super genius, but they don't realize how hard it is to put up with all the idiots in the world. (Calvin from Calvin And Hobbs)
Robert L. Johnson III
CCNA, CCDA, MCSA, CNA, Net+, A+, CHDP
VB.NET Programmer