[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 477
  • Last Modified:

DataGridView ComboBox

I have a DataGridView that contains 2 ComboBoxes called type and subtype both are getting list from query.

Question - How can I filter the second combo based on the first?
0
H-SC
Asked:
H-SC
  • 10
  • 8
1 Solution
 
Naithan ArroyoCommented:
You can do something like this.
For Each Item In Type.Items
            Dim Populate As Boolean = True
            For Each SubItem In subtype.Items
                Dim a As String = Item.ToString
                Dim B As String = Item1.ToString
                If a = B Then
                    subtype.Items.Remove(SubItem)
                End If
            Next
        Next

Open in new window

0
 
Naithan ArroyoCommented:
You can also Change the subtype list query to (through sql) Omit results
0
 
H-SCAuthor Commented:
NBIT,

Thanks, I will try this out and get back to you.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
H-SCAuthor Commented:
NBIT,

Not sure, but I may be doing something wrong.  I tried the code and no errors, but does not filter the combobox2

on drop1 I have values like

Fruit, Vegetable

on drop2 I need it to pull the correct list based on drop1

so if I select fruit from 1 then I would get a list of only fruit items in combo2
0
 
Naithan ArroyoCommented:
I Misunderstood.
Are you using SQL and VB.net with table adapters ?
0
 
H-SCAuthor Commented:
just sql based table adapters/datasets
0
 
H-SCAuthor Commented:
so the datagrid gets its data from a dataset and the 2 combos in the view get their data from datasets
0
 
Naithan ArroyoCommented:
Ok Good then do something like this

Create separate Table Adapters (TA) for the comboboxes.

First TA Do a regular Select query for the Type Combobox

Then Make another TA a Select Query in The realms of

Select SubType
From List
where Type = @Type

Then Bind the TA's  to each combobox

Finally do this type of source code to get the second combobox working.


Private Sub Type_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Type.SelectedIndexChanged
        TableAdapter.Fill(MyDataSet.Datatable, Type.SelectedText)
    End Sub

Open in new window

0
 
H-SCAuthor Commented:
ok I think that I have some of it working, I am getting an error on the type.selectedtext, does not seem to recognize it.  It does not appear to be getting the selected value and feeding it to the param
0
 
Naithan ArroyoCommented:
Change Value Member to The Value that you need feed into the TA.

Also change selectedtext to selectedvalue.

Capture.PNG
0
 
H-SCAuthor Commented:
NBIT,

the photo looks like a standard stand alone combo.  These are inside a datagridview
0
 
Naithan ArroyoCommented:
Same Thing But Change It here
Capture.PNG
0
 
Naithan ArroyoCommented:
Change On List index change to something like this


Private Sub Type_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Type.SelectedIndexChanged
        TableAdapter.Fill(MyDataSet.Datatable,Yourdatagrid.Rows.Item(Yourdatagrid.selectedindex).Cells("SUbtypeColumn").Value)
    End Sub

Open in new window

0
 
Naithan ArroyoCommented:
I meant Type Column
Private Sub Type_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Type.SelectedIndexChanged
        TableAdapter.Fill(MyDataSet.Datatable,Yourdatagrid.Rows.Item(Yourdatagrid.selectedindex).Cells("TypeColumn").Value)
    End Sub

Open in new window

0
 
Naithan ArroyoCommented:
Lets Start All Over First Have Your Data Grid Have a Data Source Of ALL Your Original Data  Like SO... (Step 1)

Capture.PNG
0
 
Naithan ArroyoCommented:
Next Convert Your Type and subtype Into ComboBoxes. Step 2

Step 3 Make Two Separate TA's For The Two Combo Boxes.

One query Being all the type's

One Query being all the Subtypes where type = @type
Capture.PNG
0
 
H-SCAuthor Commented:
yep, I have all of that correct,

It just does not like(underlined items)
"Handles type.selectedindexchanged"
and
"Acc_definTableAdapter.Fill(MCDataSet2.acc_defn, DataGridView1.Rows.Item(DataGridView1.selectedindex).Cells("type").Value)
0
 
H-SCAuthor Commented:
NBIT,

I think that I have it!  You have been a great help on this.  Many thanks for your efforts.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 10
  • 8
Tackle projects and never again get stuck behind a technical roadblock.
Join Now