?
Solved

Visual Studio 2005 ComboBox  - Limiting the items displayed in one ComboBox if a certain item is selected elsewhere

Posted on 2006-05-10
9
Medium Priority
?
271 Views
Last Modified: 2012-08-14
Hi

Is there a way of displaying only certain of the items in a ComboBox at runtimr based on other selections?

Thanks
0
Comment
Question by:Murray Brown
  • 5
  • 4
9 Comments
 
LVL 6

Expert Comment

by:willbdman
ID: 16646686
When you say other selections - other comboboxes, listboxes?

Why not populate a combobox based upon other selections?
0
 

Author Comment

by:Murray Brown
ID: 16646744
Other ComboBoxes.

Its actually in a DataGridView and I have posted the question several times.

Its a DataGridView with two ComboBox columns. So if the user makes their selection in the first row
what happens when he/she tries the second row.

Lets say the items in the comboBox in the second column are A, B & C

If B was selected in the first row  second column and then I wanted to
limit the ComboBox selection to A and C in the sercond row based on on the first column
selection.

Not sure where to begin?

Any advice would be really helpful
0
 
LVL 6

Expert Comment

by:willbdman
ID: 16647267
I assume the coboboxes are filled from a database?

Are the combox data linked in anyway?
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:Murray Brown
ID: 16647311
Hi

Thanks for the help but I think I have answered my own question.

There is no data source.

I have found that you can add items at a cellular level

So if you have a DataGridView called DGV

eg Dim DGVCel As DataGridViewComboBoxCell
    DGVCell = DGV.CurrentCell
    DGVCell.Items.clear
    DGVCell.Items.Add("hat")
0
 

Author Comment

by:Murray Brown
ID: 16647324
I now want to come up with a way to add items to a specific ComboBox Cell in a DataGridView based on a
selection in another ComboBox cell. I will awards the points on this answer
0
 
LVL 6

Expert Comment

by:willbdman
ID: 16647566
Why not have arrays for each item, so if combobox 1 SelectedIndex = 1 fill combobox2 with items from array1 etc.

0
 

Author Comment

by:Murray Brown
ID: 16647714
Hi

Would you mind giving me an example.

Thanks
0
 
LVL 6

Accepted Solution

by:
willbdman earned 2000 total points
ID: 16647916
In this example, I use two listboxes, as these can be easily filled with database data.
For this example I have filled the listboxes using a method, which is executed at load time.


Private Sub FillArray()

        Me.listbox1.Items.Add("Item1")
        Me.listbox1.Items.Add("Item2")
        Me.ListBox1.Items.Add("Item3")

        Me.ListBox2.Items.Add("Item4")
        Me.ListBox2.Items.Add("Item5")
        Me.ListBox2.Items.Add("Item6")

    End Sub


    Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged

        If ComboBox1.SelectedIndex = 0 Then

            ' Clear existing text
            ComboBox2.Items.Clear()

            ' Add new text
            For i As Integer = 0 To Me.ListBox1.Items.Count - 1

                Me.ListBox2.SelectedIndex = i
                ComboBox2.Items.Add(Me.ListBox1.SelectedItem)

            Next

        ElseIf ComboBox1.SelectedIndex = 1 Then

            ' Clear existing text
            ComboBox2.Items.Clear()

            ' Add new text
            For i As Integer = 0 To Me.ListBox2.Items.Count - 1

                Me.ListBox2.SelectedIndex = i
                ComboBox2.Items.Add(Me.ListBox2.SelectedItem)

            Next

        End If

    End Sub
0
 

Author Comment

by:Murray Brown
ID: 16647975
Great

Thanks very much for the code
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Integration Management Part 2
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses
Course of the Month15 days, 1 hour left to enroll

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question