DataGridViewComboBoxColumn problem

J

John

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["MAN_ID"];
mi.name = ds.Tables["RESULT"].Rows["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.
 
T

TheSteph

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

John

TheSteph said:
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 said:
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["MAN_ID"];
mi.name = ds.Tables["RESULT"].Rows["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.

 
J

John

John said:
TheSteph said:
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 said:
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["MAN_ID"];
mi.name = ds.Tables["RESULT"].Rows["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?
 
J

John

TheSteph said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top