Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# SQL
i want to connect a column of data gridview with type combo box to a data base and with change value of this the data source of second column with type combo box change my code is correct and work but with change first column and see data in secondd column see this error how can i solve this???
 
the following exception occured in the datagridview
system.argumentexception:datagridviewcomboboxcell value is not valid
to replace this default dialog please handle the data error event
 
please help me.........
private void foroosh_Load(object sender, EventArgs e)
        {
            DataTable p = new System.Data.DataTable();
            p = selectcolor("type","");
         (dataGridView2.Columns[0] as DataGridViewComboBoxColumn).DataSource = p;
         (dataGridView2.Columns[0] as DataGridViewComboBoxColumn).DisplayMember = "type";
         DataTable pc = new System.Data.DataTable();
            pc = sel();
         (dataGridView2.Columns[4] as DataGridViewComboBoxColumn).DataSource = pc;
         (dataGridView2.Columns[4] as DataGridViewComboBoxColumn).DisplayMember = "color";
}
 

 

 private void dataGridView2_CellEnter(object sender, DataGridViewCellEventArgs e)
        {
 
            DataTable pe = new System.Data.DataTable();
            string pi;
            int f;
            if (e.ColumnIndex == 2)
            {
                pe = selectcolor("tip", "where type= '" + dataGridView2.Rows[0].Cells[0].Value.ToString() + "'");
                (dataGridView2.Columns[2] as DataGridViewComboBoxColumn).DataSource = pe;
                (dataGridView2.Columns[2] as DataGridViewComboBoxColumn).DisplayMember = "tip";
            }
            else if(e.ColumnIndex == 1)
            {
                pi = varab(dataGridView2.Rows[e.RowIndex].Cells[0].Value.ToString());
                if (pi == "ميلادي")
                {
                    for (f = 1950; f <= 2020; f++)
                        (dataGridView2.Columns[1] as DataGridViewComboBoxColumn).Items.Add(f);
                }
                else
                {
                    for (f = 1300; f <= 1400; f++)
                        (dataGridView2.Columns[1] as DataGridViewComboBoxColumn).Items.Add(f);
                }
            }
 

            }
Posted 23-Dec-12 19:08pm
Edited 23-Dec-12 19:25pm
v2
Comments
Krunal Rohit at 24-Dec-12 1:09am
   
Provide your code...

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

  Permalink  

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



Advertise | Privacy | Mobile
Web02 | 2.8.141022.2 | Last Updated 24 Dec 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100