Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > How to set Value of a DataGridViewComboBoxCell
 

How to set Value of a DataGridViewComboBoxCell

i have a gridthat has 3 columns among them one is a DataGridViewComboBoxColumn
am adding colums programatically while loading the form. as


DataGridViewComboBoxColumn Col1=new DataGridViewComboBoxColumn();
Col1.Name="UOM";
Col1.DataSourse=dt;
Col1.ValueMember="id";
Col1.DisplayMember="Name";

the problem is that when i display data back to the grid ,i cant assign thevalue

like

dataGridView1.Rows[1].Cells["UOM"].Value=12;
dataGridView1.Rows[2].Cells["UOM"].Value=14;

it throws an Exceptions saying
System.Format Exception the DataGridViewCmboboxCell Value is not valid

somebody please help....


Dare To Explore
  • Moved bynobugzMVP, ModeratorSunday, March 15, 2009 1:26 PMnot a bcl q (Moved from .NET Base Class Library to Windows Forms Data Controls and Databinding)
  •  
Bijithbal  Saturday, March 14, 2009 12:27 PM
Are you sure that the value you're trying to set exists within the datasource?
Elohim  Saturday, March 14, 2009 11:13 PM
Hi Bjjithbal,

Why not try to handle the dataerror event of the datagridview?

private void yourDataGridView_DataError(object sender, DataGridViewDataErrorEventArgs e)
{
e.Cancel = true;
}


moongazer  Monday, March 16, 2009 4:55 AM
Are you sure that the value you're trying to set exists within the datasource?
Elohim  Saturday, March 14, 2009 11:13 PM
Hi Bjjithbal,

Why not try to handle the dataerror event of the datagridview?

private void yourDataGridView_DataError(object sender, DataGridViewDataErrorEventArgs e)
{
e.Cancel = true;
}


moongazer  Monday, March 16, 2009 4:55 AM

You can use google to search for other answers

Custom Search

More Threads

• How to set datagridview columns manadatory.
• How to split the column Heading of Datagrid in Two rows
• Need Help: StackOverflowException on DatagridView RowValidating event
• How to set the property of the form as Modal
• datagrid column format date
• Form validation -validate everything at once
• Grouping and formatting the columns in datagridview
• empty Cell??????
• Host Shockwave (flash 8) ActiveX in DataGridViewCell
• winform datagrid error