473,394 Members | 1,821 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,394 software developers and data experts.

Setting value for unbound DataGridViewComboBoxCell

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 value. The objects live in the
DataGridViewComboBoxColumn.Items, but there is no way of getting an object
out based on, e.g. display value.

Here's the type :

private class complexObj
{
public string id_string;
public int id;

public complexObj(string Id_string, int Id)
{
id_string = Id_string;
id = Id;
}

public String ShowVal
{
get { return id_string; }
set { id_string = value; }
}

public complexObj Self
{
get { return this; }
}
}
here's the code that fills the pulldown list and attempts to fill the
grid...

private void Form1_Load(object sender, EventArgs e)
{
(grid.Columns["Column2"] as DataGridViewComboBoxColumn).ValueMember =
"Self";
(grid.Columns["Column2"] as DataGridViewComboBoxColumn).DisplayMember
= "ShowVal";

complexObj mi = new complexObj("One", 1);
(grid.Columns["Column2"] as DataGridViewComboBoxColumn).Items.Add(mi);
mi = new complexObj("Two", 2);
(grid.Columns["Column2"] as DataGridViewComboBoxColumn).Items.Add(mi);
mi = new complexObj("Three", 3);
(grid.Columns["Column2"] as DataGridViewComboBoxColumn).Items.Add(mi);

int pos = grid.Rows.Add();
grid.Rows[pos].Cells["Column1"].Value = "First line";
grid.Rows[pos].Cells["Column2"].Value = "One"; // doesn't
work, woudl like to assign straight out of

// (grid.Columns["Column2"] as
DataGridViewComboBoxColumn).Items
pos = grid.Rows.Add();
grid.Rows[pos].Cells["Column1"].Value = "Second line";
grid.Rows[pos].Cells["Column2"].Value = "Two"; // doesn't
work

pos = grid.Rows.Add();
grid.Rows[pos].Cells["Column1"].Value = "Third line";
grid.Rows[pos].Cells["Column2"].Value = "Three"; // doesn't
work

}
--

"I have nothing but the greatest respect for other peoples' crackpot
beliefs".
-- Sam the Eagle.

May 26 '06 #1
0 5438

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

Similar topics

2
by: John Hargrove | last post by:
I'm having trouble setting decimal place values in the results field of a sample management database I'm building for an environmental testing laboratory. The degree of sensitivity varies among...
2
by: Bex | last post by:
Hi All. I'm attempting at the moment to set the recordsource of an unbound subform when i open up it's main form. My view is to have one intial form - called "Search" which has a number of...
1
by: simon | last post by:
I have an unbound RTF2 control in an Access 2003 form which I set to show either unformatted text or else text with words and sentences highlighted. I do this by setting the PlainText property,...
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...
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...
3
by: Andrus | last post by:
I have DataGridView in virtual mode containing 3500 rows. In code below, assigning to RowCount value to 3500 takes 8 seconds. CPU usage goes high at this time. Stepping by F11 into user code shows...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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.