Hello,
I have a datagridview it contains 3 comboboxes, when combo1(category) is selected, the combo2(sub-Category)sub-Category value will display, when the combo2(sub-Category) is selected combo3(price)price value will display. every thing is working fine for the first row. when i do same thing in the second row the combo2 contains the previous sub-category and combo3 contains previous price how to restrict it.
please go throught the code if something is missing
code:
Thanks in advance
saha
I have a datagridview it contains 3 comboboxes, when combo1(category) is selected, the combo2(sub-Category)sub-Category value will display, when the combo2(sub-Category) is selected combo3(price)price value will display. every thing is working fine for the first row. when i do same thing in the second row the combo2 contains the previous sub-category and combo3 contains previous price how to restrict it.
please go throught the code if something is missing
code:
VB.NET:
Public ddlCategory As DataGridViewComboBoxColumn = New DataGridViewComboBoxColumn()
Public ddlSubCategory As DataGridViewComboBoxColumn = New DataGridViewComboBoxColumn()
Public ddlPrice As DataGridViewComboBoxColumn = New DataGridViewComboBoxColumn()
-----------------------------------------------------------------
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
ddlCategory.Name = "Category"
ddlSubCategory.Name = "SubCategory"
ddlPrice.Name = "Price"
DataGridView1.Columns.Insert(0, ddlCategory)
DataGridView1.Columns.Insert(1, ddlSubCategory)
DataGridView1.Columns.Insert(2, ddlPrice)
Dim scmd As String = "select distinct Category from master"
Dim sqlda As New SqlDataAdapter(scmd, strCon)
sqlda.Fill(DS, "ProjNo")
ddlCategory.DataSource = DS.Tables("Category")
ddlCategory.DisplayMember = "Category"
ddlCategory.ValueMember = "Category"
sqlda.Dispose()
sqlda = Nothing
DataGridView1.Rows.Add(3)
End Sub
------------------------------------------------------------------------
Private Sub DataGridView1_EditingControlShowing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewEditingControlShowingEventArgs) Handles DataGridView1.EditingControlShowing
cb = TryCast(e.Control, ComboBox)
If cb IsNot Nothing Then
RemoveHandler cb.SelectedIndexChanged, AddressOf DGVddlCategoryComboIndexChanged
RemoveHandler cb.SelectedIndexChanged, AddressOf DGVddlSubCategoryComboIndexChanged
Select Case gvMultipleProjects.CurrentCell.ColumnIndex
Case 0
AddHandler cb.SelectedIndexChanged, AddressOf DGVddlCategoryComboIndexChanged
Case 1
AddHandler cb.SelectedIndexChanged, AddressOf DGVddlSubCategoryComboIndexChanged
End Select
End If
End Sub
----------------------------------------------------------------------
Private Sub DGVddlCategoryComboIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
Dim com As ComboBox = CType(sender, ComboBox)
Dim scmd As String = "select distinct SubCategory from master where Category='" & com.SelectedItem.ToString() & "'"
Dim sqlda As New SqlDataAdapter(scmd, strCon)
sqlda.Fill(DS, "SubCategory")
ddlSubCategory.DataSource = DS.Tables("SubCategory")
ddlSubCategory.DisplayMember = "SubCategory"
ddlSubCategory.ValueMember = "SubCategory"
sqlda.Dispose()
sqlda = Nothing
RemoveHandler cb.SelectedIndexChanged, AddressOf DGVddlCategoryComboIndexChanged
RemoveHandler cb.SelectedIndexChanged, AddressOf DGVddlProjNoComboIndexChanged
End Sub
----------------------------------------------------------------
Private Sub DGVddlSubCategoryComboIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
Dim com As ComboBox = CType(sender, ComboBox)
Dim scmd As String = "select price from master where SubCategory=" & com.SelectedValue.ToString() & ""
Dim sqlda As New SqlDataAdapter(scmd, strCon)
sqlda.Fill(DS, "Price")
ddlPrice.DataSource = DS.Tables("Price")
ddlPrice.DisplayMember = "Price"
ddlPrice.ValueMember = "id"
sqlda.Dispose()
sqlda = Nothing
RemoveHandler cb.SelectedIndexChanged, AddressOf DGVddlCategoryComboIndexChanged
RemoveHandler cb.SelectedIndexChanged, AddressOf DGVddlSubCategoryComboIndexChanged
End Sub
Thanks in advance
saha