473,387 Members | 1,501 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,387 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 8597
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.