Click here to Skip to main content
15,886,720 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hi All,

ComboBoxA change event to display comboboxB values filter by starting letters loading from two different tables.

Pls help me.

table1
DigitalCode
1234567890
2345678901
3456789012
4567890123

table2
dgGrp
12
23
3456
456

comboboxA comboboxB

1234567890 12
2345678901 23
3456789012 3456
4567890123 456
Posted
Updated 13-Jan-15 15:09pm
v5
Comments
Sergey Alexandrovich Kryukov 13-Jan-15 20:58pm    
Not a question, not clear. Help with what? Match what? What is your problem?
—SA
NALAM1 13-Jan-15 21:05pm    
now i updated. pls
BillWoodruff 13-Jan-15 22:50pm    
What you describe only makes sense to me if you have separate content you want displayed in the second ComboBox for each choice the user makes in the first ComboBox.

It appears here all you are doing is just showing one value in the second ComboBox when the selected value changes in the first ComboBox ... do I not understand you ?

1 solution

Well, from what I can deduce you wanna do I would use the following:

C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace TestApp
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private string[] table2 = new string[] { "12", "23", "3456", "456" };

        private void comboBoxA_SelectedIndexChanged(object sender, EventArgs e)
        {
            // Find filter char
            char selectedChar = comboBoxA.Text[0];

            // Clear combo box
            comboBoxB.SelectedIndex = -1;
            comboBoxB.Items.Clear();

            // Repopulate by selected char
            for (int i = 0; i < table2.Length; i++)
            {
                if (table2[i][0] == selectedChar)
                {
                    comboBoxB.Items.Add(table2[i]);
                }
            }
        }
    }
}
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900