472,363 Members | 2,111 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,363 software developers and data experts.

VB2005 - Sort DataGridView on Text (FormattedValue) of a ComboBoxcolumn instead of underlying value?

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 tell me if this is even possible, and if
so, how to do it? If this is completely impossible, how would you suggest going
about sorting a ComboBox wherein the text displayed in the column is the
client's name, and the underlying value is an ID?

Thanks,
Matt
Jun 17 '06 #1
4 8475
Matt,

I do probably not understand your question, but to sort a datagridview is
typical used a dataview.
The property of that is a text(string) property.

http://msdn2.microsoft.com/en-us/lib...view.sort.aspx

Is that what you need?

Cor

"Matt" <br**********@community.nospam> schreef in bericht
news:em**************@TK2MSFTNGP02.phx.gbl...
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 tell me if this is even
possible, and if so, how to do it? If this is completely impossible, how
would you suggest going about sorting a ComboBox wherein the text displayed
in the column is the client's name, and the underlying value is an ID?

Thanks,
Matt

Jun 17 '06 #2
Cor,

Unfortunately, this does not solve my problem, since it still leaves me unable
to sort by the actual text being displayed in the field, since that text is not
a part of the base DataTable object (it is being referenced in through another
DataSource on the ComboBox Column). What I need is a way to sort on what's
*actually showing* in the ComboBox Column, as opposed to any data that underlies
it. Is this possible?

Thanks,
Matt

Cor Ligthert [MVP] wrote:
Matt,

I do probably not understand your question, but to sort a datagridview is
typical used a dataview.
The property of that is a text(string) property.

http://msdn2.microsoft.com/en-us/lib...view.sort.aspx

Is that what you need?

Cor

"Matt" <br**********@community.nospam> schreef in bericht
news:em**************@TK2MSFTNGP02.phx.gbl...
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 tell me if this is even
possible, and if so, how to do it? If this is completely impossible, how
would you suggest going about sorting a ComboBox wherein the text displayed
in the column is the client's name, and the underlying value is an ID?

Thanks,
Matt


Jun 17 '06 #3
Matt,

In my idea is the column that is related to the combobox always a column in
an underlaying table. The combobox is only used to fill it with values.

Why can you not sort on that using the dataview, did you try it already?

Be aware that the sort never standard is working while updating a row in a
datagrid(view).

I hope this helps,

Cor
"Matt" <br**********@community.nospam> schreef in bericht
news:%2******************@TK2MSFTNGP02.phx.gbl...
Cor,

Unfortunately, this does not solve my problem, since it still leaves me
unable to sort by the actual text being displayed in the field, since that
text is not a part of the base DataTable object (it is being referenced in
through another DataSource on the ComboBox Column). What I need is a way
to sort on what's *actually showing* in the ComboBox Column, as opposed to
any data that underlies it. Is this possible?

Thanks,
Matt

Cor Ligthert [MVP] wrote:
Matt,

I do probably not understand your question, but to sort a datagridview is
typical used a dataview.
The property of that is a text(string) property.

http://msdn2.microsoft.com/en-us/lib...view.sort.aspx

Is that what you need?

Cor

"Matt" <br**********@community.nospam> schreef in bericht
news:em**************@TK2MSFTNGP02.phx.gbl...
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 tell me if this is
even possible, and if so, how to do it? If this is completely
impossible, how would you suggest going about sorting a ComboBox wherein
the text displayed in the column is the client's name, and the
underlying value is an ID?

Thanks,
Matt


Jun 18 '06 #4
Hi Matt,

Thank you for posting.

If you have a DataGridViewComboBoxColumn in your DataGridView, you have to
set the DataSource of the DataGridView to populate data in it. That's to
say, you must bind the DataGridView to a datasource.

If you set the SortMode of the DataGridViewComoboBoxColumn to Automatic,
you can sort this column by clicking it. The sorting is based on the cells'
value in the column, not the FormattedValue. If you want to sort this
column based on the FormattedValue, it seems that you have to customize the
sorting.

There're several options for custom sort of DataGridView. These options are
listed below.
1. Calling DataGridView.Sort(DataGridViewColumn,ListSortDirec tion) method
2. Handling with the DataGridView's SortCompare event
3. Calling DataGridView.Sort(IComparer) method

You can refer to the below link for more information on the above three
options:
http://msdn2.microsoft.com/en-us/lib...08(d=ide).aspx

4. Using DataView and set the its Sort property

You can refer to he below link for more information on the option4:
http://msdn2.microsoft.com/en-us/lib...sort(d=ide).as
px

It seems that only option2 and option3 could be applied to sort the
DataGridViewComboBoxColumn based on the FormattedValue. However, these two
options only apply under the condition that the DataGridView is NOT bounded
to a DataSource.

So in my opinion, it is impossible to sort a DataGridViewComboBoxColumn
based on the FormattedValue.

If you have other concerns, please don't hesitate to let me know.

Sincerely,
Linda Liu
Microsoft Online Community Support

================================================== ==
When responding to posts,please "Reply to Group" via
your newsreader so that others may learn and benefit
from your issue.
================================================== ==

Jun 23 '06 #5

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

Similar topics

6
by: Fred Phase | last post by:
The following button definition works fine in Mozilla where the value "in" is assigned to "awol_status". In Internet Explorer 6.0.2800.1106 on Win 2K the value "switch status" is assigned to...
2
by: charles-brewster | last post by:
I'm trying to write a simple JavaScript function which will use a button to copy table cell data into a form input text box as the "value" attribute. The following is intended to test the...
2
by: Bill nguyen | last post by:
I need help to set selected value of combobox column in DGV. I went this far then got stuck on what to do next:. How do I set "selected Value" of comboboxpayCode to value of column PayCode ?...
3
by: joey.powell | last post by:
I have a datagridview where I set its "DataSource" property to a DataSet and its "DataMember" property to a table within the DataSet. I need for the DataGridView to "sort" through the contents of...
2
maxamis4
by: maxamis4 | last post by:
I have a text box that holds a value of 300 how do I make it show $ 300.00, not to mention their are multiple records that have 1200, 900, and I want them to display with the dollar sign.
2
by: tee | last post by:
Hi, How do i sort datagridview programmically, current i have the following code but i keep get the error saying "DataGridView control must be bound to an IBindingList object to be sorted.", ...
5
by: usa51 | last post by:
Hi, I have a dropdown options value from 2 to 5. After I change the selection, in the same asp page, I also have a button "Add", how do I dynamically add 3 text fields if I select value 3 and then...
3
by: Frederik | last post by:
Hi group, I have a DataGridView that is mainly consisting of data bound columns. One column however is unbound. I'm not able to sort the grid on this column! Is that normal behaviour? If so,...
3
by: frenzy99 | last post by:
Can some one help me with this problem. I want to sort DataGridView based on the order in which values were added, not on the basis of any particular column, unlike the functionality provided by...
2
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and credentials and received a successful connection...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
1
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
1
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...
0
by: Johno34 | last post by:
I have this click event on my form. It speaks to a Datasheet Subform Private Sub Command260_Click() Dim r As DAO.Recordset Set r = Form_frmABCD.Form.RecordsetClone r.MoveFirst Do If...
1
by: ezappsrUS | last post by:
Hi, I wonder if someone knows where I am going wrong below. I have a continuous form and two labels where only one would be visible depending on the checkbox being checked or not. Below is the...

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.