473,407 Members | 2,306 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,407 software developers and data experts.

DataGridViewComboBoxColumn problem


Hi,

I've been trying to populate a DataGridViewComboBoxColumn with objects.
The object is defined as :

private struct manufactItem
{
public string name;
public Guid? man_id;

public override string ToString()
{
return name;
}
}

And they are inserted like so :

for (int i = 0; i < ds.Tables["RESULT"].Rows.Count; i++)
{
mi = new manufactItem();
mi.man_id = (Guid)ds.Tables["RESULT"].Rows[i]["MAN_ID"];
mi.name = ds.Tables["RESULT"].Rows[i]["NAME"].ToString();

int pos = (dgvManAlternatives.Columns["ALT_MANUFACTURER"] as
DataGridViewComboBoxColumn).Items.Add(mi);
}
This is all well and good, and when the cell on the grid is clicked the
pulldown list is populated. The problem I am having is when I move out of
the cell, I get

"DataGridViewComboBoxCell value is not valid"

Can I only put string values into the DataGridViewComboBoxColumn?

John.

--

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

May 19 '06 #1
4 7532

Are you sure that the value in the grid is equal to one of the value
populated in the Combobox ?
"John" <ju**@junk.com> wrote in message
news:e4**********@perki.connect.com.au...

Hi,

I've been trying to populate a DataGridViewComboBoxColumn with objects.
The object is defined as :

private struct manufactItem
{
public string name;
public Guid? man_id;

public override string ToString()
{
return name;
}
}

And they are inserted like so :

for (int i = 0; i < ds.Tables["RESULT"].Rows.Count; i++)
{
mi = new manufactItem();
mi.man_id = (Guid)ds.Tables["RESULT"].Rows[i]["MAN_ID"];
mi.name = ds.Tables["RESULT"].Rows[i]["NAME"].ToString();

int pos = (dgvManAlternatives.Columns["ALT_MANUFACTURER"] as
DataGridViewComboBoxColumn).Items.Add(mi);
}
This is all well and good, and when the cell on the grid is clicked the
pulldown list is populated. The problem I am having is when I move out of
the cell, I get

"DataGridViewComboBoxCell value is not valid"

Can I only put string values into the DataGridViewComboBoxColumn?

John.

--

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

May 19 '06 #2

"TheSteph" <Th******@NoSpam.com> wrote in message
news:%2******************@TK2MSFTNGP04.phx.gbl...

Are you sure that the value in the grid is equal to one of the value
populated in the Combobox ?

Hmmm. There are no values in the grid, this is on editing a new row. I think
I need to set up an initial value for the column.


"John" <ju**@junk.com> wrote in message
news:e4**********@perki.connect.com.au...

Hi,

I've been trying to populate a DataGridViewComboBoxColumn with objects.
The object is defined as :

private struct manufactItem
{
public string name;
public Guid? man_id;

public override string ToString()
{
return name;
}
}

And they are inserted like so :

for (int i = 0; i < ds.Tables["RESULT"].Rows.Count; i++)
{
mi = new manufactItem();
mi.man_id = (Guid)ds.Tables["RESULT"].Rows[i]["MAN_ID"];
mi.name = ds.Tables["RESULT"].Rows[i]["NAME"].ToString();

int pos = (dgvManAlternatives.Columns["ALT_MANUFACTURER"] as
DataGridViewComboBoxColumn).Items.Add(mi);
}
This is all well and good, and when the cell on the grid is clicked the
pulldown list is populated. The problem I am having is when I move out of
the cell, I get

"DataGridViewComboBoxCell value is not valid"

Can I only put string values into the DataGridViewComboBoxColumn?

John.

--

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


May 21 '06 #3

"John" <ju**@junk.com> wrote in message
news:e4**********@perki.connect.com.au...

"TheSteph" <Th******@NoSpam.com> wrote in message
news:%2******************@TK2MSFTNGP04.phx.gbl...

Are you sure that the value in the grid is equal to one of the value
populated in the Combobox ?

Hmmm. There are no values in the grid, this is on editing a new row. I
think I need to set up an initial value for the column.


"John" <ju**@junk.com> wrote in message
news:e4**********@perki.connect.com.au...

Hi,

I've been trying to populate a DataGridViewComboBoxColumn with objects.
The object is defined as :

private struct manufactItem
{
public string name;
public Guid? man_id;

public override string ToString()
{
return name;
}
}

And they are inserted like so :

for (int i = 0; i < ds.Tables["RESULT"].Rows.Count; i++)
{
mi = new manufactItem();
mi.man_id = (Guid)ds.Tables["RESULT"].Rows[i]["MAN_ID"];
mi.name = ds.Tables["RESULT"].Rows[i]["NAME"].ToString();

int pos = (dgvManAlternatives.Columns["ALT_MANUFACTURER"] as
DataGridViewComboBoxColumn).Items.Add(mi);
}
This is all well and good, and when the cell on the grid is clicked the
pulldown list is populated. The problem I am having is when I move out
of
the cell, I get

"DataGridViewComboBoxCell value is not valid"

Can I only put string values into the DataGridViewComboBoxColumn?

John.


Initialization is not the problem. I think this has something to do with the
MemberValue. It looks like a DataGridViewComboBox just wont work with
anything other than strings unless it is being used in a bound mode. Somehow
I have to provide it functionality to do a lookup from the string value
selected to the actual object that string represents.

Anyone know how?

May 23 '06 #4

"TheSteph" <Th******@NoSpam.com> wrote in message
news:%2******************@TK2MSFTNGP04.phx.gbl...

Are you sure that the value in the grid is equal to one of the value
populated in the Combobox ?


If anyone cares, I believe the solution is that I need to set the
DisplayMember to a member of the object type I am inserting into the combo
box items list, and I need to set the ValueMember to a member of the object
type I want to actually see as the .Value for a selected item.
May 24 '06 #5

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

Similar topics

1
by: Shawn | last post by:
I am trying to use a DataGridView to display one column of textboxes with a single value from a query and then next to it have a combobox that displays results from another query. What happens is...
3
by: philip | last post by:
I have a datagridview with some columns. One of them has been declared as a DatagridviewComboboxColumn The datasource of this column is a table of an Access Database. There is 13000 lines in...
3
by: Rain County | last post by:
I am programmatically building and populating a table and then making it the data source for a dataGridView. I want to add a column to the dataGridView which will be a DataGridViewComboBoxColumn. ...
0
by: Simon Tamman | last post by:
How do other people get around having to define the ValueMember in a DataGridViewComboBoxColumn when binding to a list of business objects? I'm currently doing the following, and it feels wrong...
0
by: Ken | last post by:
Hi I have a little application that does datavalidation. It supports dynamically loaded plugins (you drop a dll with a class implementing IValidator<Tin the same dir as the main application)....
1
by: sklett | last post by:
I have a DataGridView bound to a custom business object. The business object has 2 attributes that are FKs to a lookup table (think HairColorID, EyeColorID, etc) For these 2 columns I have...
0
by: =?ISO-8859-2?B?UmFmYbMgR2llemdhs2E=?= | last post by:
I have: protected void InitControls() { gvProfile.AutoGenerateColumns = false; DataTable dtProfile = new DataTable("KFS"); // dodajemy kolumny foreach(DataGridViewColumn dc in...
0
by: ajey | last post by:
hi all! Im doing a windows application (C#), i have a datagridview bound from a Sql database in which i want one column to be ComboBox.I use DataGridViewComboBoxColumn and bind that column value.......
1
by: =?Utf-8?B?RWQgQ29oZW4=?= | last post by:
I have tried to use the DataGridComboBoxColumn object with limited success. What I want to do is to create one new unbound column to be a combo box (so far, this has worked), populate it with items...
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: 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: 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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.