Click here to Skip to main content
Sign Up to vote bad
good
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:08
Edited 23 Dec '12 - 19:25

Comments
Krunal Rohit - 24 Dec '12 - 1:09
Provide your code...

1 solution

  Permalink  

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

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 484
1 Mahesh Bailwal 398
2 Maciej Los 215
3 CPallini 175
4 Aarti Meswania 173
0 Sergey Alexandrovich Kryukov 9,417
1 OriginalGriff 7,204
2 CPallini 3,933
3 Rohan Leuva 3,211
4 Maciej Los 2,743


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