473,385 Members | 1,912 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Set Value of DataGridViewComboBoxCell

Hello-

I'm having a dickens of a time trying to set the value on a
DataGridViewComboBoxColumn. I actually have two DataGridViewComboBoxColumns
in my datagrid view.

First, I'm setting up the grid/column as follows..

DataGridViewComboBoxColumn someColumn = new
DataGridViewComboBoxColumn();
panelColumn.DisplayIndex = 0;
panelColumn.HeaderText = "SomeHeader";
panelColumn.DataSource = myDataSource; // myDataSource is of
type List<MyInterestingClass>
panelColumn.DisplayMember = "StringMember"; // StringMember
is of type string
panelColumn.Name = "Whatever";
panelColumn.ValueMember = "InterestingValue"; //
InterestingValue is a type of a custom class, i.e., MyInterestingClass
frm.dataGridView1.Columns.Add(panelColumn);
However, when I try to set the cell value, I get an exception:

DataGridViewComboBoxCell cell =
(DataGridViewComboBoxCell)frm.dataGridView1["Whatever", row];
cell.Value = cell.Items[0]; // exception: Unable to
cast object of type 'MyInterestingClass' to type 'System.String'.
call.Value = myDataSource[0]; // exception: Unable to
cast object of type 'MyInterestingClass' to type 'System.String'.

I don't understand why it is trying to cast to System.String... perhaps to
display the value in the DataGridViewComboBoxCell? This doesn't make sense,
though, because you set the .DisplayMember.

??
Jun 27 '08 #1
0 3360

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
by: cwizard | last post by:
I'm calling on a function from within this form, and there are values set but every time it gets called I get slammed with a run time error... document.frmKitAmount.txtTotalKitValue is null or not...
0
by: John | last post by:
Hi, I have set a DataGridViewComboBoxColumn for a complex object type, and set the DisplayMember and ValueMember to members of the object type. My problem is how to programmatically set the cell...
2
by: kofteros | last post by:
I have a DataGridView in which one of its columns is a DatagridViewCombobox. This column contains values as 1. "ROAMING" 2. "MOBILE" 3. "TELEPHONY"... I want to select an index from this...
1
by: hangdee | last post by:
I have a DatagridviewComboBoxCell with self added object (with an id and a string field) as items to the DatagridviewComboBoxCell. Dim cboCell As New DataGridViewComboBoxCell...
0
by: Bruno Neves Pires Silva | last post by:
Hello, everybody. How can I get the selected item index in a DataGridViewComboBoxCell, in a datagridview?
0
by: =?Utf-8?B?R2FkeUM=?= | last post by:
HI I populate one col. in a dataiewgrid with a combocell as DataGridViewComboBoxCell. (create on the fly and assign it to cell) I need to avid arrow user's up/down on that cells. All the grid...
1
by: JB | last post by:
Hi All, Is there a way to programmatically open the drop down list of a DataGridViewComboBoxCell? Thanks JB
4
by: Martin Horst | last post by:
Hi, I've got a Windows Form DataGridView with several DataGridViewComboBoxCell columns. The Items collection of the DataGridViewComboBoxCell can take any kind of objects. But when the user...
2
by: =?Utf-8?B?RHJEQkY=?= | last post by:
I understand that the Value put into a DataGridViewComboBoxCell has to be a member of the Items list or an exception is thrown. I also understand that you can override that exception by handling...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.