By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,781 Members | 1,373 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,781 IT Pros & Developers. It's quick & easy.

DataGridViewComboBoxColumn problem

P: n/a

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
Share this Question
Share on Google+
4 Replies


P: n/a

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

P: n/a

"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

P: n/a

"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

P: n/a

"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 discussion thread is closed

Replies have been disabled for this discussion.