Click here to Skip to main content
15,891,653 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have a Datagrid in which I have a Datagridcombo box(editable), I have populated the combobox manually by using the following code.
C#
DataGridViewComboBoxColumn Actioncolumn = new DataGridViewComboBoxColumn();
            Actioncolumn.DataPropertyName = "ZSL_Action";
            Actioncolumn.HeaderText = "Action";
            string[] installs = new string[] { "red", "white", "green" };
            Actioncolumn.Items.AddRange(installs);
            //Actioncolumn.Items.Add("red");
            //Actioncolumn.Items.Add("white");
            //Actioncolumn.Items.Add("green");
            Actioncolumn.ReadOnly = false;
            dataGridView1.Columns.Add(Actioncolumn);

Now when I try to change the combo box value, DataError occurs. What shall I do.

Also by default only 1st value(i.e., Red) is assigned to the combo box. What shall I do.
Posted
Updated 13-Dec-11 21:30pm
v2

1 solution

I have generally found that if you are adding a new item in the DataGridView this will happen. You need to implement the DataError event to capture these without showwing an error to the user.

What is happening is that the DataBoundObject on the row has a value (usually NULL if you are adding a new item) that does not exist in the combobox.
 
Share this answer
 
Comments
samitha.sweety 20-Dec-11 7:05am    
I have handled dataerror by implementing dataerror event but when im trying to change the combo box i cant perform any other action for every move of mouse dataerror event is triggered.

Also why am i getting the 1st value as default.
Mathew Crothers 20-Dec-11 17:13pm    
What is the data source you are using for the DataGridView. I'm assuming that there is a public property in the dataset that has the name ZSL_Action

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