Click here to Skip to main content
15,881,938 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi I am filtering my datagridview using a combobox. I wanna get a message telling me that the choosen value can't be found because the column name doesn't exit in the datagridview.
where I'm stock is the second else if statement.

C#
private void cbFilterEU_SelectedIndexChanged(object sender, EventArgs e)
        {
            
            string check = cbFilterEU.SelectedItem.ToString();
            if (check == "All")
            {
                MessageBox.Show("All Data !!!");

            }

            else if (cbFillFilterEIU.SelectedItem != null)
            {
                //Check an see what's in the dgv
                DataView dv = new DataView(dt);
                // now filter
                dv.RowFilter = " [Areacode] = " + cbFilterEU.Text.Trim();
                MessageBox.Show("AREACODE");
                datagridview1.DataSource = dv;
            }
		else if
{
/* Wanna look through the datagridview for the column name and if not present show message
                MessageBox.Show("Can't find the column");
             */
}


I tried something like this but no success

C#
//else if (cbFilterEU.SelectedItem != null && datagridview1 == null)
           //{
           //    MessageBox.Show("Can't find the column");
           //}
Posted

Your last "else if" will not be called in the case the SelectedItem is not null
 
Share this answer
 
Hi
You can try

datagridview1 .Rows.Count<=0;


instead of datagridview1 == null
 
Share this answer
 
Comments
mikybrain1 24-Feb-15 4:53am    
hiI did tried that one but it threw an exception at the level:

dv.RowFilter = " [Areacode] = " + cbFilterEU.Text.Trim();

The Column can't be found.
I wanna have a message instead of the exception
Jeet Gupta 24-Feb-15 4:59am    
if you want to have a message instead of the exception then you can use try catch for exception hanndling.

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