RE: Filtering on a combobox
- From: Vanessa <Vanessa@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Tue, 1 Apr 2008 05:50:06 -0700
Hi "Saimvp"!
If I have all 3 table in a dataset, can't I filter the combobox via
databinding?
I don't want to fill combobox record by record.
Thank you
Vanessa
"Saimvp" wrote:
Gud day. Hi and Hello.
1.) Load your combobox with your vendors name/id. (like your example).
2.) Try this Code at you class.
public void FillCombo(ComboBox cb, string sSql, string sTable, int
sNum)
{
OleDbConnection CON = new OleDbConnection();
CON.ConnectionString = clsvar.DBAddress;
CON.Open();
OleDbCommand cmd = new OleDbCommand(sSql, CON);
DataSet ds = new DataSet();
long totalRow = 0;
//Set the Data Adapter
OleDbDataAdapter da = new OleDbDataAdapter(sSql, CON);
da.Fill(ds, sTable);
totalRow = ds.Tables[sTable].Rows.Count - 1;
cb.Items.Clear();
for (int i = 0; i <= totalRow; i++) cb.Items.Add("" +
ds.Tables[sTable].Rows[i].ItemArray.GetValue(sNum).ToString());
if (cb.Items.Count > 1) cb.SelectedIndex = 0;
}
3.) Then try to call that procedure at you load button.
private void loadbutton_Click(object sender, EventArgs e)
{
MYClass.FillCombo(combo, "select customerid from customer where
customerid = '" + combobox.text + "'", "admin", 1);
}
I hope this codes help you.
Thanks and God Bless
--
To be Happy is To be Yourself
"Vanessa" wrote:
Hi all!
I have a many to many relationship and I need to filter a combobox with
related records. I have the following tables:
- Vendors
- Customers
- Vendors X Customers
So, one vendor is related to many customers and vice-versa.
I have a combobox with vendors. When I select one vendor I need to filter
the other combobox with the customers related to the vendor.
How can I do this?
Thanks in advance,
Vanessa
- References:
- RE: Filtering on a combobox
- From: Saimvp
- RE: Filtering on a combobox
- Prev by Date: Re: Newbie question on string operators in C#
- Next by Date: how i should solve slash / problem
- Previous by thread: RE: Filtering on a combobox
- Next by thread: Handle of a Bitmap
- Index(es):