|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
DataGridView and ComboBoxI 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 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 <dadoing1@newsgroups.nospam> schreef in bericht Show quoteHide quote news:OmajiqHzGHA.5048@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 > 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/library/system.windows.forms.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/download.aspx?PageId=1&ItemId=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/subscriptions/managednewsgroups/default.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/subscriptions/support/default.aspx. ================================================== This posting is provided "AS IS" with no warranties, and confers no rights. 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?ID=28fdf87c-e705-4a75-8285-29ce9ff01d75 :-) I hope this helps,Cor ""Jeffrey Tan[MSFT]"" <je***@online.microsoft.com> schreef in bericht Show quoteHide quote news:X5jOSzMzGHA.4548@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/library/system.windows.forms.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/download.aspx?PageId=1&ItemId=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/subscriptions/managednewsgroups/default.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/subscriptions/support/default.aspx. > ================================================== > This posting is provided "AS IS" with no warranties, and confers no > rights. > 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/MultiColumnFlatCombo.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/subscriptions/managednewsgroups/default.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/subscriptions/support/default.aspx. ================================================== This posting is provided "AS IS" with no warranties, and confers no rights. 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/scripts/ShowCode.asp?txtCodeId=2934&lngWId=10 :-) I send it here because it add to the thread in my idea.Cor ""Jeffrey Tan[MSFT]"" <je***@online.microsoft.com> schreef in bericht Show quoteHide quote news:I2pcg7MzGHA.400@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/MultiColumnFlatCombo.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/subscriptions/managednewsgroups/default.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/subscriptions/support/default.aspx. > ================================================== > This posting is provided "AS IS" with no warranties, and confers no > rights. > 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.com> wrote in message Show quoteHide quote news:I2pcg7MzGHA.400@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/MultiColumnFlatCombo.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/subscriptions/managednewsgroups/default.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/subscriptions/support/default.aspx. > ================================================== > This posting is provided "AS IS" with no warranties, and confers no > rights. > 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/subscriptions/managednewsgroups/default.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/subscriptions/support/default.aspx. ================================================== This posting is provided "AS IS" with no warranties, and confers no rights. 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/subscriptions/managednewsgroups/default.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/subscriptions/support/default.aspx. ================================================== This posting is provided "AS IS" with no warranties, and confers no rights.
FOR ALL - Best Practices for navigating within code? -plus - Add-In's that help?
Where can we buy VB.net? How Microsoft does it? Multiple icons into 1 exe or dll Sending email from Windows application Not working. crystal report question how to get parent control of the context menu stip Progress bar to run with the datachecking Service station petrol pump interface show something while loading .Net framework |
|||||||||||||||||||||||