I have Combobox A, and Combobox B. Both combox A and B are related to each other.
Combobox A : Color serial No
Combobox B : Color part No
Note: Color serial No, and Color part No belongs to a color type.
if user select an item in combo box A, combo box B will populate exists Color part No that are related to Color serial No. from the dataset or database.
or
if user select an item in combo box B combo box A will populate exists Color serial No that are related to Color part No.
from the dataset or database.
I am basically limiting the user to only query the items that only exist relate to each other by color serial and part no.
Can someone give me an ideal to effectively design this logic. At the moment.
Loading
David SmithPosted Feb 7, 2012, 12:26 PM
Keep in mind there is two combo boxes, and they are both related to each other, so they can select any item from either combo box. So if i to reload the combo box base upon the item select in the combo box, the minute i select an item in combo box a , I have to reload the combo box B with the related records, vi versa etc.........
can you also tell which is the quicker way for the data to return faster then what its doing, I am using linq to pull from from the database.
I am using similiar below, and its slow, the database only have three records at the moment. Any suggestions.
example:
IF ComboBox A is selected first then do this below
{
var List = from l in colorTableAdapter.GetData
where l.ColorSerialNumber == ComboBoxA.Text
select l,
ComboBoxB.Datasource = List.Select( t => t.ColorPartNo).ToList();
}
ELSE
{
var List = from l in colorTableAdapter.GetData
where l.ColorPartNumber == ComboBoxB.Text
select l,
ComboBoxA.Datasource = List.Select( t => t.ColorSerialNo).ToList();
}
Satyapriya NayakPosted Feb 7, 2012, 7:54 AM
Try this...
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;
using System.Data.OleDb;
namespace Comboboxs
{
public partial class Form1 : Form
{
string ConnectionString = System.Configuration.ConfigurationSettings.AppSettings["dsn"];
OleDbCommand com;
OleDbDataAdapter oda;
DataSet ds;
string str;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
comboBox1.Items.Add("Choose Color serial No");
OleDbConnection con = new OleDbConnection(ConnectionString);
con.Open();
str = "select * from Color";
com = new OleDbCommand(str, con);
OleDbDataReader reader = com.ExecuteReader();
while (reader.Read())
{
comboBox1.Items.Add(reader["ColorserialNo"]);
}
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
comboBox2.Items.Clear();
OleDbConnection con = new OleDbConnection(ConnectionString);
con.Open();
str = "select * from Color where ColorserialNo='" + comboBox1.Text.Trim() + "'";
com = new OleDbCommand(str, con);
OleDbDataReader reader = com.ExecuteReader();
while (reader.Read())
{
comboBox2.Items.Add(reader["ColorpartNo"].ToString());
}
con.Close();
reader.Close();
}
}
}
Thanks