473,320 Members | 1,865 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,320 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 26357
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: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

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.