By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,480 Members | 755 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,480 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Share this Question
Share on Google+
4 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.