Click here to Skip to main content
13,003,934 members (128,165 online)
Rate this:
Please Sign up or sign in to vote.
See more:
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);
                    for (f = 1300; f <= 1400; f++)
                        (dataGridView2.Columns[1] as DataGridViewComboBoxColumn).Items.Add(f);

Posted 23-Dec-12 19:08pm
Updated 23-Dec-12 19:25pm
Krunal Rohit 24-Dec-12 1:09am
Provide your code...

1 solution

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

Solution 1


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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170627.1 | Last Updated 24 Dec 2012
Copyright © CodeProject, 1999-2017
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