Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / July 2006

Tip: Looking for answers? Try searching our database.

Sorting of DataGridViewComboBoxColumn type columns

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
nvx - 17 Jul 2006 19:53 GMT
Hi,
is it possible to sort DataGridViewComboBoxColumn type columns by
clicking on the header cell (in DataGridViewColumnSortMode.Automatic
case)? It doesn't seem to work or there is a bug in my code. There
should be an arrow sign (triangle) in the header cell after clicking on
it, but there doesn't appear any...

Thanks for any help.

With regards
nvx
Kevin Spencer - 17 Jul 2006 20:39 GMT
Yes, it's possible, but I don't know why you're having a problem.

Signature

HTH,

Kevin Spencer
Microsoft MVP
Professional Chicken Salad Alchemist

What You Seek Is What You Get.

> Hi,
> is it possible to sort DataGridViewComboBoxColumn type columns by
[quoted text clipped - 7 lines]
> With regards
> nvx
nvx - 18 Jul 2006 06:42 GMT
Thank you for the information. I'll try to go through the code and find
the problem.

One more thing: is there any other property of
DataGridViewComboBoxColumn columns that HAS to be set to some value for
this to work (except the DataGridViewColumnSortMode.Automatic; I'm
generating the DataGridViewComboBoxColumn columns on the fly...)?

Many thanks...

With regards
nvx

> Yes, it's possible, but I don't know why you're having a problem.
>
[quoted text clipped - 18 lines]
> > With regards
> > nvx
Kevin Spencer - 18 Jul 2006 11:30 GMT
Are you using a DataSource for the columns? Are you setting the SortMode? I
have found the following White Paper helpful:

http://download.microsoft.com/download/5/6/4/5646742C-3EB7-48F7-BFB3-CC295D618CF
9/DataGridView%20FAQ.doc


Signature

HTH,

Kevin Spencer
Microsoft MVP
Professional Chicken Salad Alchemist

What You Seek Is What You Get.

> Thank you for the information. I'll try to go through the code and find
> the problem.
[quoted text clipped - 31 lines]
>> > With regards
>> > nvx
nvx - 18 Jul 2006 12:25 GMT
Thank you very much, I'll read the document. It looks very useful.

Yes, DataSource for the ComboBox items is an ArrayList of Strings.
SortMode is set to Automatic when I programatically add the
DataGridViewComboBoxColumn column into the DataGridView.

With regards
nvx

> Are you using a DataSource for the columns? Are you setting the SortMode? I
> have found the following White Paper helpful:
[quoted text clipped - 45 lines]
> >> > With regards
> >> > nvx
Kevin Spencer - 18 Jul 2006 16:16 GMT
I meant, are you using a DataSource for the DataGridView columns?

Signature

HTH,

Kevin Spencer
Microsoft MVP
Professional Chicken Salad Alchemist

What You Seek Is What You Get.

> Thank you very much, I'll read the document. It looks very useful.
>
[quoted text clipped - 56 lines]
>> >> > With regards
>> >> > nvx
nvx - 18 Jul 2006 17:14 GMT
I'm sorry, I must have misunderstood.

Yes, the DataGridView is bound to an Access database table. After the
grid is filled with data, user can add or remove
DataGridViewComboBoxColumn columns.

Kevin Spencer napsal(a):
> I meant, are you using a DataSource for the DataGridView columns?
nvx - 18 Jul 2006 19:18 GMT
Well, it seems I didn't have set the DataPropertyName correctly. Due to
certain things one letter was in lowercase and everything went wrong.

Uff, I'm glad it's working... :)

Kevin, thank you very much for your help.

With regards
nvx

nvx napsal(a):
> I'm sorry, I must have misunderstood.
>
[quoted text clipped - 4 lines]
> Kevin Spencer napsal(a):
>> I meant, are you using a DataSource for the DataGridView columns?
whittetinternet@earthlink.net - 26 Jul 2006 22:46 GMT
I also have a problem doing this.  It doesn't seem to work out of the
box and I'm not sure which method is the best to choose to solve it.  I
have the DataGridView FAQ and it is great, but in this case it appears
that having a DataSource assigned is hurting my options of sorting on a
field not assigned to the DataSource's DataTable.

I have a DataGridView bound to a DataTable.  I then add a
DataGridViewComboBoxColumn and this all works.  Now when I click this
column the sort apprears to sort on the ID instead of the NAME
displayed in the combo box.
I have
cbo.DataPropertyName = "SalesUnitID"
cbo.DisplayMember = "NAME";  //Name from the SalesUnit table.
cbo.ValueMember = "ID";  //ID from the SalesUnit table.

--The e-mail is trash, post your response please:)

> Well, it seems I didn't have set the DataPropertyName correctly. Due to
> certain things one letter was in lowercase and everything went wrong.
[quoted text clipped - 15 lines]
> > Kevin Spencer napsal(a):
> >> I meant, are you using a DataSource for the DataGridView columns?
whittetinternet@earthlink.net - 26 Jul 2006 22:48 GMT
I also have a problem doing this.  It doesn't seem to work out of the
box and I'm not sure which method is the best to choose to solve it.  I
have the DataGridView FAQ and it is great, but in this case it appears
that having a DataSource assigned is hurting my options of sorting on a
field not assigned to the DataSource's DataTable.

I have a DataGridView bound to a DataTable.  I then add a
DataGridViewComboBoxColumn and this all works.  Now when I click this
column the sort apprears to sort on the ID instead of the NAME
displayed in the combo box.
I have
cbo.DataPropertyName = "SalesUnitID"
cbo.DisplayMember = "NAME";  //Name from the SalesUnit table.
cbo.ValueMember = "ID";  //ID from the SalesUnit table.

--The e-mail is trash, post your response please:)

> Well, it seems I didn't have set the DataPropertyName correctly. Due to
> certain things one letter was in lowercase and everything went wrong.
[quoted text clipped - 15 lines]
> > Kevin Spencer napsal(a):
> >> I meant, are you using a DataSource for the DataGridView columns?
whittetinternet@earthlink.net - 26 Jul 2006 22:54 GMT
Here is what I have now:
dataView.Sort = dataGridView.SortedColumn.Name + " " +
               (direction == ListSortDirection.Ascending ?
               "ASC " : "DESC ");

Do I need to databind to a dataView with the sort?

Right now I am using a single DataTable for the binding to the grid and
a second dataTable for the Sales Unit combobox's DataSource.

So the following only sorts on the ID.  Would the solution be to put
both DataTables in a DataSet and then sort on the view with the column
being sorted being "Parent(SalesUnit).Name"?

whittetinter...@earthlink.net wrote:
> I also have a problem doing this.  It doesn't seem to work out of the
> box and I'm not sure which method is the best to choose to solve it.  I
[quoted text clipped - 32 lines]
> > > Kevin Spencer napsal(a):
> > >> I meant, are you using a DataSource for the DataGridView columns?
Kevin Spencer - 27 Jul 2006 03:44 GMT
You'll have to forgive me. It's late, and I've put in a long day (in a long
series of long days!). In addition, I haven't worked on this particular
project for awhile, and the DataGridView is one complex critter, so I may be
a bit lax in my recollection. But I do want to help, so I'll try to point
you in the right direction.

I believe you're on the right track. As I recall, it is necessary to use
parent/child relationships, and possibly a combination of two related
DataTables to do this, perhaps even a custom View from the DataSet. I know
that's not much, but I'm afraid it's all I have time for right now. In fact,
I should probably go to bed!

Signature

HTH,

Kevin Spencer
Microsoft MVP
Professional Chicken Salad Alchemist

Sequence, Selection, ZZZZZZZZzzzzzzzzzzzzzzzzzzzzzzzz.......................

> Here is what I have now:
> dataView.Sort = dataGridView.SortedColumn.Name + " " +
[quoted text clipped - 47 lines]
>> > > Kevin Spencer napsal(a):
>> > >> I meant, are you using a DataSource for the DataGridView columns?
whittetinternet@earthlink.net - 27 Jul 2006 18:22 GMT
Happy to receive the help.

The solution with a databound grid that I used was to add an
DataColumn.Expression to the combo box column and use that column to
sort using the click event of the DataGridView column header and set
the dataView.Sort = "MyColumnNAME ASC";

Also, we had a request to display an inserted row in Rows[0] after each
insert.  This solution will help solve that too.

> You'll have to forgive me. It's late, and I've put in a long day (in a long
> series of long days!). In addition, I haven't worked on this particular
[quoted text clipped - 68 lines]
> >> > > Kevin Spencer napsal(a):
> >> > >> I meant, are you using a DataSource for the DataGridView columns?

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.