• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 482
  • 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
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

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