Windows Develop Bookmark and Share   
 index > Windows Forms Designer > datagridview combobox
 

datagridview combobox

i have a datagridview containing 8 columns in which datagridviewcombobox is 8th column (index is 7)

3 variables :

Double a=1,b=2,c=3;

these 3 variables should appear in that combobox for every row,please tell me how to do this..

Also the command for retrieving the selected value.

Thanks in Advance !

  • Moved byOmegaManMVPWednesday, May 27, 2009 12:13 AM (From:Visual C# General)
  •  
Bhaskar - kgtrm  Tuesday, May 26, 2009 6:51 PM
Bhaskar, You need to handle data event error in order to avoid the exception message box. The message box itself will show that you need to handle data error event. This is because when adding a new row, the value of the cell would be null or empty string. But the combo box expects it to be any of the combobox items. If you want your combo box to display names and get values you can use enum as combo box item as follows public enum enum1 { a = 1 ,b = 2,c = 3 }; comboBox1.Items.Add(enum1.a); comboBox1.Items.Add(enum1.b); comboBox1.Items.Add(enum1.c); private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { enum1 e1 = (enum1)(comboBox1.SelectedItem); int i = (int)e1; MessageBox.Show(i.ToString()); } Thanks, Nanda
HUMONGOUSAUR  Wednesday, May 27, 2009 11:53 AM
Dear Bhaskar, Have you tried the following code DataGridViewComboBoxColumn c7 = dataGridView1.Columns[70] as DataGridViewComboBoxColumn; c7.Items.Add(a); c7.Items.Add(b); c7.Items.Add(c); Thanks, Nanda
HUMONGOUSAUR  Wednesday, May 27, 2009 7:20 AM
actually i know that,but when i select any one of those values from the combobox,i am getting the following error System.ArgumentException : Datagridcombobox cell value is not valid What to do ? ---Also, This is a normal combobox.. Double a=10,b=20; ArrayList mm = new ArrayList(); mm.Add(a); mm.Add(b); comboBox1.DataSource = mm; from the above code i am able to see the "values" directly, but i want the names "a" and "b" to appear in that combobox and when they are selected they should give their values.. Please tell me how?
Bhaskar - kgtrm  Wednesday, May 27, 2009 10:09 AM
Bhaskar, You need to handle data event error in order to avoid the exception message box. The message box itself will show that you need to handle data error event. This is because when adding a new row, the value of the cell would be null or empty string. But the combo box expects it to be any of the combobox items. If you want your combo box to display names and get values you can use enum as combo box item as follows public enum enum1 { a = 1 ,b = 2,c = 3 }; comboBox1.Items.Add(enum1.a); comboBox1.Items.Add(enum1.b); comboBox1.Items.Add(enum1.c); private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { enum1 e1 = (enum1)(comboBox1.SelectedItem); int i = (int)e1; MessageBox.Show(i.ToString()); } Thanks, Nanda
HUMONGOUSAUR  Wednesday, May 27, 2009 11:53 AM
Thanks !
Bhaskar - kgtrm  Thursday, May 28, 2009 1:00 AM

You can use google to search for other answers

Custom Search

More Threads

• Problem with custom CodeDomSerializer with UserControl
• About winform UI like options in vs
• I want to have the first column in the ListView as a LinkLabel in Windows Forms.
• Is it possible to filter properties displayed for a CollectionEditor (without using ICustomTypeDescriptor)
• Bug, anchored control on inherited form, System.Windows.Forms
• mimic MaskedTextBox.TextMaskFormat
• Prevent my Component from appearing in component tray?
• Incorrect positions of controls on form with Menu (VS2003)
• VS 2005 Winform designer Issue
• Form Inheritance - Designer adds code