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

DataGridView and ComboBox

I am sure this has been asked and answered, but here goes anyway...

VS.Net 2005, VB.Net

How can you display more than one field in the displaymember property of a
combobox inside the datagridview control? I am at a loss.

Thanks,
David
Aug 30 '06 #1
8 26338
David,

You cannot in any combobox of Net use more columns in the displaymember of a
combobox. There is a standard multicolumn combobox to find on InterNet but I
have never seen such a one for inside another control.

If you want to display however by instance a first name and a last name
using a bounded table, than you can create an extra column in you datatable.
If you don't know how, reply.

I hope this helps,

Cor

<da******@newsgroups.nospamschreef in bericht
news:Om**************@TK2MSFTNGP05.phx.gbl...
>I am sure this has been asked and answered, but here goes anyway...

VS.Net 2005, VB.Net

How can you display more than one field in the displaymember property of a
combobox inside the datagridview control? I am at a loss.

Thanks,
David

Aug 31 '06 #2
Hi David,

Based on my understanding, you want to display a dropdown list of items in
each Combobox of DataGridViewComboBoxColumn. If I have misunderstood you,
please feel free to tell me, thanks.

The programming model of DataGridViewComboBoxColumn can be found in the
link below, also, there is sample code in the link of populating the
combobox with a list of items:
http://msdn2.microsoft.com/en-us/lib...datagridviewco
mboboxcolumn.aspx

We can populate the dropdownlist of combobox in DataGridViewComboBoxColumn
with DataGridViewComboBoxColumn.Items property. Please refer to
SetAlternateChoicesUsingItems method in the above sample code.

The key point is that the items populated in the list must be correspond to
the datasource data value of DataPropertyName from DataGridView
databinding. The datasource data of DataPropertyName is used as the
SelectedValue property of the Combobox. The DataGridView databinding
requires looking up the value in the combobox items and getting the display
value for the item. During this process, if the cell's value cannot be
found in the combo box items collection it raises the DataError event.
Let's take the above sample code as an example:
In above DataGridView databinding, the DataGridView will display employees
table from northwind sample database.
DataGridViewComboBoxColumn.DataPropertyName is set to *TitleOfCourtesy*
field in CreateComboBoxColumn() method. So, to populate the
DataGridViewComboBoxColumn.Items property, we should take care to assign
items corresponding to the data of *TitleOfCourtesy* field, such as "Mr.",
"Ms.", "Mrs.", "Dr.". If we assign other data to the Items property instead
of above 4 candidate values, the databinding will fail to find a
selectedvalue in dropdownlist, and DataError event is raised.

Once you take care of this key point, you should can use
DataGridViewComboBoxColumn without any problem.

Additionally, Microsoft .Net Winform team has maintained a wonderful
DataGridView FAQ with samples in the link below. After you download it, in
the DataGridView FAQ, you will find a lot of guidelines regarding using
DataGridView, also a dedicated topic with DataGridViewComboBoxColumn in
section 3.5:
http://www.windowsforms.net/Samples/...mId=220&tabind
ex=4

Hope this helps.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Aug 31 '06 #3
Oh, after viewing Cor's reply, I suspect I have misunderstood you. It seems
that you are looking for a multicolumn combobox in DataGridView.

Yes, just as Cor pointed out, there is no build-in combobox support for
this, since DataGridView internally leverages combobox, so we can not get
this in DataGridView.

However, we can customize to create a multicolumn combobox in .Net, and
since the DataGridView has a rich feature of hosting controls, we can
create a customized DataGridViewMultiColumnComboBoxColumn to host this
multicolumn combobox.

To create a multicolumn combobox, we have several solutions, some use
ListView to host in the dropdown list, some use other options, please refer
to the 2 articles below as a start:
http://www.codeproject.com/vb/net/multicolumncombo.asp
http://www.codeproject.com/vb/net/Mu...nFlatCombo.asp

Hope this helps and sorry for the misunderstanding.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Aug 31 '06 #4
Jeffrey,

Thank you for the showing us that sample page. A pity is that the vb samples
that I saw are obvious by a converter created C# code and in my idea not in
VB.Net style as the VB team would make them.

As well are those I have seen, when they are binded, based on the Northwind
dataset. Special because for this reason we did make this weekend a sample
about a combobox binded to a dataset on the fly. I saw no combobox sample in
what you have showed us, so therefore does this maybe add to this thread.

http://www.vb-tips.com/default.aspx?...5-29ce9ff01d75

:-)

I hope this helps,

Cor

""Jeffrey Tan[MSFT]"" <je***@online.microsoft.comschreef in bericht
news:X5**************@TK2MSFTNGXA01.phx.gbl...
Hi David,

Based on my understanding, you want to display a dropdown list of items in
each Combobox of DataGridViewComboBoxColumn. If I have misunderstood you,
please feel free to tell me, thanks.

The programming model of DataGridViewComboBoxColumn can be found in the
link below, also, there is sample code in the link of populating the
combobox with a list of items:
http://msdn2.microsoft.com/en-us/lib...datagridviewco
mboboxcolumn.aspx

We can populate the dropdownlist of combobox in DataGridViewComboBoxColumn
with DataGridViewComboBoxColumn.Items property. Please refer to
SetAlternateChoicesUsingItems method in the above sample code.

The key point is that the items populated in the list must be correspond
to
the datasource data value of DataPropertyName from DataGridView
databinding. The datasource data of DataPropertyName is used as the
SelectedValue property of the Combobox. The DataGridView databinding
requires looking up the value in the combobox items and getting the
display
value for the item. During this process, if the cell's value cannot be
found in the combo box items collection it raises the DataError event.
Let's take the above sample code as an example:
In above DataGridView databinding, the DataGridView will display employees
table from northwind sample database.
DataGridViewComboBoxColumn.DataPropertyName is set to *TitleOfCourtesy*
field in CreateComboBoxColumn() method. So, to populate the
DataGridViewComboBoxColumn.Items property, we should take care to assign
items corresponding to the data of *TitleOfCourtesy* field, such as "Mr.",
"Ms.", "Mrs.", "Dr.". If we assign other data to the Items property
instead
of above 4 candidate values, the databinding will fail to find a
selectedvalue in dropdownlist, and DataError event is raised.

Once you take care of this key point, you should can use
DataGridViewComboBoxColumn without any problem.

Additionally, Microsoft .Net Winform team has maintained a wonderful
DataGridView FAQ with samples in the link below. After you download it, in
the DataGridView FAQ, you will find a lot of guidelines regarding using
DataGridView, also a dedicated topic with DataGridViewComboBoxColumn in
section 3.5:
http://www.windowsforms.net/Samples/...mId=220&tabind
ex=4

Hope this helps.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no
rights.

Aug 31 '06 #5
Jeffrey,

It are a lot of replies from me today, I find this multicolumn combobox much
nicer. The ones you show are easier to do with just an extra datatable
column with an expression in that as I tried to tell in my first reply.

However this one is very nice and easy to use.

http://www.planet-source-code.com/vb...2934&lngWId=10

:-)

I send it here because it add to the thread in my idea.

Cor

""Jeffrey Tan[MSFT]"" <je***@online.microsoft.comschreef in bericht
news:I2*************@TK2MSFTNGXA01.phx.gbl...
Oh, after viewing Cor's reply, I suspect I have misunderstood you. It
seems
that you are looking for a multicolumn combobox in DataGridView.

Yes, just as Cor pointed out, there is no build-in combobox support for
this, since DataGridView internally leverages combobox, so we can not get
this in DataGridView.

However, we can customize to create a multicolumn combobox in .Net, and
since the DataGridView has a rich feature of hosting controls, we can
create a customized DataGridViewMultiColumnComboBoxColumn to host this
multicolumn combobox.

To create a multicolumn combobox, we have several solutions, some use
ListView to host in the dropdown list, some use other options, please
refer
to the 2 articles below as a start:
http://www.codeproject.com/vb/net/multicolumncombo.asp
http://www.codeproject.com/vb/net/Mu...nFlatCombo.asp

Hope this helps and sorry for the misunderstanding.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no
rights.

Aug 31 '06 #6
Everyone, thanks for all the information. I will let you know which option
I choose and post some code for everyone to look at.

David

""Jeffrey Tan[MSFT]"" <je***@online.microsoft.comwrote in message
news:I2*************@TK2MSFTNGXA01.phx.gbl...
Oh, after viewing Cor's reply, I suspect I have misunderstood you. It
seems
that you are looking for a multicolumn combobox in DataGridView.

Yes, just as Cor pointed out, there is no build-in combobox support for
this, since DataGridView internally leverages combobox, so we can not get
this in DataGridView.

However, we can customize to create a multicolumn combobox in .Net, and
since the DataGridView has a rich feature of hosting controls, we can
create a customized DataGridViewMultiColumnComboBoxColumn to host this
multicolumn combobox.

To create a multicolumn combobox, we have several solutions, some use
ListView to host in the dropdown list, some use other options, please
refer
to the 2 articles below as a start:
http://www.codeproject.com/vb/net/multicolumncombo.asp
http://www.codeproject.com/vb/net/Mu...nFlatCombo.asp

Hope this helps and sorry for the misunderstanding.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no
rights.

Aug 31 '06 #7
Hi David,

Thanks for your feedback!

Ok, I will continue to monitor this thread. Please feel free to feedback
any progress and concerns, thanks.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Sep 1 '06 #8
Hi David,

How about this issue? Have you managed to customize these samples to your
need? Is your problem resolved?

If you still have any concern or need any help, please feel free to
feedback, thanks.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Sep 5 '06 #9

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

Similar topics

4
by: Aaron Smith | last post by:
Ok, this is an odd one, but I could use some assistance with the framework 2 in VB.Net... I want to have a DataGridViewColumn, only have it use the ComboBox, then when they drop down the...
3
by: Art | last post by:
Hi, Forgive me for posting this message in 2 groups -- it appears that the Data Access group isn't very active, so I'm posting again here: I have a DataTable that I want to fill using a...
4
by: Matt | last post by:
I have been searching all over the web for a way to sort a DataGridView based on the actual text being shown in a ComboBox column as opposed to the underlying value (an ID in this case). Can anyone...
0
by: c_shah | last post by:
I have the controls on my form display the values of the currently selected row of the DataGridView. I am binding my DataGridView to a collection (Collection - which implements IBindingList...
3
by: sklett | last post by:
I'm changing from a DataGrid to a DataGridView and have run across a problem. The items that are bound to the DataGrid have an int Property that represents a primary key of a lookup table in my...
8
by: Brian Pelton | last post by:
This is on .Net 2.0 in a WinForms application. I have a DataGridView that is bound to a BindingSource. The DataGridView has 3 columns. The first two are "normal" text columns and the last is a...
2
by: David Jackson | last post by:
Hello, I have an unbound DataGridView of which one of the columns is a ComboBox colum containing category data, plus an additional option called <newSo when the ComboBox is dropped down it looks...
3
by: =?Utf-8?B?Sm9obiBCdW5keQ==?= | last post by:
New to databinding in vs2005, I always did it manually in 2003. I have no problem loading comboboxes, and a change in that combobox changes the data in the textboxes but I can not figure out a way...
18
by: Andrus | last post by:
Marc, Thank you very much. I have issue on implementing add row properly using this. User presses down arrow in last row in grid starting adding new row. Then user changes its mind desiding...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...

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.