ComboBox in DataGrid

G

Guest

I'm trying to implement the age-old task of placing a combobox in a datagrid's tablestyle like I usually do in Windows Forms. I've seen an example at http://www.opennetcf.org/forums/topic.asp?TOPIC_ID=941 but still it isn't what I need

There are two tables: one is the source of the datagrid (Customers) with the field "id_customer_type", essentially a foreign key to a lookup table (Customer_Types), which contains the columns "id_customer_type" (the PK) and "name" (readable text)

Is there a way to set up a combobox with "datamember" and "valuemember", so the user sees the "pretty name" of the customer type instead of it's unique id? If not, what other ways are there to do this? The source table is sent to a Web Service that expects a certain type of dataset, so adding more (and redundant) columns with the "name" field seems going in the wrong direction
 
J

jez

yep, sure thing!

I use comboBox.DataSource = myDataTable;
comboBox.DisplayMember = "NiceName";
comboBox.ValueMember = "dataMember";

New CF programmer said:
I'm trying to implement the age-old task of placing a combobox in a
datagrid's tablestyle like I usually do in Windows Forms. I've seen an
example at http://www.opennetcf.org/forums/topic.asp?TOPIC_ID=941 but still
it isn't what I need.
There are two tables: one is the source of the datagrid (Customers) with
the field "id_customer_type", essentially a foreign key to a lookup table
(Customer_Types), which contains the columns "id_customer_type" (the PK) and
"name" (readable text).
Is there a way to set up a combobox with "datamember" and "valuemember",
so the user sees the "pretty name" of the customer type instead of it's
unique id? If not, what other ways are there to do this? The source table
is sent to a Web Service that expects a certain type of dataset, so adding
more (and redundant) columns with the "name" field seems going in the wrong
direction.
 
G

Guest

Thanks jez
But this combobox needs to be one of the columns of a datagrid


----- jez wrote: ----

yep, sure thing

I use comboBox.DataSource = myDataTable
comboBox.DisplayMember = "NiceName"
comboBox.ValueMember = "dataMember"

New CF programmer said:
I'm trying to implement the age-old task of placing a combobox in
datagrid's tablestyle like I usually do in Windows Forms. I've seen a
example at http://www.opennetcf.org/forums/topic.asp?TOPIC_ID=941 but stil
it isn't what I needthe field "id_customer_type", essentially a foreign key to a lookup tabl
(Customer_Types), which contains the columns "id_customer_type" (the PK) an
"name" (readable text)so the user sees the "pretty name" of the customer type instead of it'
unique id? If not, what other ways are there to do this? The source tabl
is sent to a Web Service that expects a certain type of dataset, so addin
more (and redundant) columns with the "name" field seems going in the wron
direction
 
G

Guest

Still unresolved - I'm sure I'm not the only one with this problem
I don't need editing capability, but I need all the rows to show their corresponding value
For example

If I have a table (Customers) such as
id_customer, lastname, firstname, id_customer_typ
1, Smith, Bob,
2, Jones, Fred,
Where id_customer_type is linked to the following table (Customer types
id_customer_type, descriptio
1, Old and establishe
2, Still gaining trus
3, New partnershi

How can I get the datagrid to display
1, Smith, Bob, Old and establishe
2, Jones, Fred, Old and establishe

Thanks to anyone who can help!!

----- New CF programmer wrote: ----

I'm trying to implement the age-old task of placing a combobox in a datagrid's tablestyle like I usually do in Windows Forms. I've seen an example at http://www.opennetcf.org/forums/topic.asp?TOPIC_ID=941 but still it isn't what I need

There are two tables: one is the source of the datagrid (Customers) with the field "id_customer_type", essentially a foreign key to a lookup table (Customer_Types), which contains the columns "id_customer_type" (the PK) and "name" (readable text)

Is there a way to set up a combobox with "datamember" and "valuemember", so the user sees the "pretty name" of the customer type instead of it's unique id? If not, what other ways are there to do this? The source table is sent to a Web Service that expects a certain type of dataset, so adding more (and redundant) columns with the "name" field seems going in the wrong direction.
 
A

anamika

If you want the DisplayMember to be different than the ValueMember, then you
can't simply add strings to the ComboBox. I always use an
SqlDataAdapter to fill a DataTable. Then I reference two different columns.

Dim da As New SqlDataAdapter("SELECT id_customer_type,
ISNULL(description, '') FROM Customers", cn)
Dim tbl As New DataTable
da.Fill(tbl)
comboBox.DataSource = tbl
comboBox.ValueMember = "id_customer_type"
comboBox.DisplayMember = "Description"


Hope it helps

Anamika
 

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