Click here to Skip to main content
15,898,222 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have 3 comboboxes


each combobox data binds from another combobox source

for eg.

student type = dayscholar
hostel
---

if i select dayscholar the another combobox shows student name

if i select student name, the third combobox shows student marks

problem is

how to validate combobox (select or not)

i tried selectedindex, selecteditem, text but no use




C#
private void cmbtype_SelectedIndexChanged(object sender, EventArgs e)
      {
          if (cmbtype.Text == string.Empty)
              return;


SQL
//bind name combobox1
         OleDbdatadapter da = new OleDbdatadapter("select name,id from member_master where Subscribe_Type='" + cmbtype.Text.Trim() + "'  order by name", con);

C#
ds = new DataSet();
da.Fill(ds);
cmbname.Items.Insert(0, string.Empty);
cmbname.DataSource = ds.Tables[0];
cmbname.DisplayMember = "name";
cmbname.ValueMember = "id";



C#
}

private void cmbname_SelectedIndexChanged(object sender, EventArgs e)
{
    if (cmbname.SelectedIndex <= 0)
        return;
    gen_table();
}

private void cmbfor_SelectedIndexChanged(object sender, EventArgs e)
{
    if (cmbfor.Text != "")
        gen_table();
}
private void gen_table()
{
    if (cmbtype.SelectedItem == null)
        return;
    //if (comboBox1.SelectedItem     == null)
    //    return;
    //if (comboBox1.SelectedValue  == null)
    //    return;
    //if (comboBox1.Text  == null)
    //    return;
    if (cmbname.SelectedIndex == 0)
        return;

}
}
Posted
Updated 7-Mar-14 0:52am
v3
Comments
Amalraj Ramesh 7-Mar-14 6:20am    
if you bind the combo box properly
selected value defiantly will work
For better solution post your code logic
Arun_Ramasamy 7-Mar-14 7:53am    
Thank u i follow tommie tolmay416
[no name] 7-Mar-14 6:23am    
what have you tried for combobox validation yet if you will share it then anyone can help you.
Arun_Ramasamy 7-Mar-14 7:54am    
thank u i follow tommie tolmay416
ZurdoDev 7-Mar-14 6:36am    
Why won't selectedindex work?

try this.

Please remember to rate my answer.


/// Check If combobox text is selected

if (!string.IsNullOrWhiteSpace(cmbtype.Text))

{

{
 
Share this answer
 
Comments
Arun_Ramasamy 7-Mar-14 7:20am    
private void cmbtype_SelectedIndexChanged(object sender, EventArgs e)
{
//bind name combobox1
OleDbDataAdapter da = new OleDbDataAdapter("select name,id from member_master where Subscribe_Type='" + cmbtype.Text.Trim() + "' order by name", con);
ds = new DataSet();
da.Fill(ds);
cmbname.Items.Insert(0, string.Empty);
cmbname.DataSource = ds.Tables[0];
cmbname.DisplayMember = "name";
cmbname.ValueMember = "id";
cmbname.SelectedIndex = -1;
}

private void cmbname_SelectedIndexChanged(object sender, EventArgs e)
{


/// Check If combobox text is selected

if (!string.IsNullOrWhiteSpace(cmbname.Text))
return;
gen_table();
}

return not work properly,
Arun_Ramasamy 7-Mar-14 7:53am    
thanku so much
Dr Drastic 8-Mar-14 4:15am    
My Pleasure!!!
C#
private void cmbtype_SelectedIndexChanged(object sender, EventArgs e)
        {
              //bind name combobox1
            OleDbDataAdapter da = new OleDbDataAdapter("select name,id from member_master where Subscribe_Type='" + cmbtype.Text.Trim() + "'  order by name", con);
            ds = new DataSet();
            da.Fill(ds);
            cmbname.Items.Insert(0, string.Empty);
            cmbname.DataSource = ds.Tables[0];
            cmbname.DisplayMember = "name";
            cmbname.ValueMember = "id";
            cmbname.SelectedIndex = -1;
}

   private void cmbname_SelectedIndexChanged(object sender, EventArgs e)
        {


            /// Check If combobox text is selected

            if (!string.IsNullOrWhiteSpace(cmbname.Text))
{   /////
            return;
            gen_table();
        
}  /////

your code should be inbetween the brackets.
 
Share this answer
 

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