473,406 Members | 2,867 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,406 software developers and data experts.

how in the world do i sort a datagridview?

nev
251 100+
i gotta form2 with a datagridview control. data is entered in it programatically.

i wanna do form2.datagridview.sort(what will i put here???, direction)

definitely a string or integer for a columnindex is not valid. so how will i reference the current datagridviewcolumn. i noticed there is datagridview.currentrow but where's datagridview.currentcolumn??? did microsoft forgot about it?
Oct 1 '07 #1
5 1740
QVeen72
1,445 Expert 1GB
Hi,

Why not set this property of datagridview:

AllowUserToOrderColumns = True

REgards
Veena
Oct 1 '07 #2
jamesd0142
469 256MB
also add a sort order into your sql statement if you using 1
Oct 1 '07 #3
nev
251 100+
Hello Veena, but isn't that property only used to allow a user to rearrange the columns?

Hi jamesd0142, I use a For Next loop to enter data to my datagridview. Data comes from 3 different bindingsource. I would like to physically manipulate the sorting of the datagridview I have filled with values.

For example I have filled my datagridview with values...

____|col1|col2|
row1|_B_|_2_|
row2|_C_|_3_|
row3|_A_|_1_|

I wanna sort it by col1...

datagridview.sort(???col1???, system.componentmodel.listsortdirection.ascending)

____|col1|col2|
row1|_A_|_1_|
row2|_B_|_2_|
row3|_C_|_3_|

The first parameter should be a datagridviewcolumn type. If I place "col1" or datagridview.currentcell.columnindex, naturally it won't work. I also noticed that the datagridview.columns property has getpreviouscolumn and getnextcolumn but he got no getcolumn or getcurrentcolumn.

Maybe I'll try placing the cursor to col2 and use getpreviouscolumn, but this is dumb. Anyone knows the correct way to do this please help.
Oct 2 '07 #4
nev
251 100+
MWAHAHAA!!! I got it. I GOT IT!!! I can't believe i got it! I finally know how to reference the current datagridviewcolumn!!!
Oct 2 '07 #5
jamesd0142
469 256MB
Awsome, what i was suggesting was in you select statement add an order by clause.

e.g. select columnname from tablename where parameters = ??? order by columnname1, columnname2...

cheers
Oct 3 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: thomasp | last post by:
I have a datagridview that allows the user to sort the column by clicking on the header of the column the user wishes to sort. I did not code this, it had the ability when the datagrid was...
4
by: Matt | last post by:
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...
3
by: martin1 | last post by:
All, ..Net 2.0 DataGridView column sort is automatic, I don't want column sort, is anybody know how to not sort column in DataGridView? Thanks
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
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.", ...
3
by: Freddy Coal | last post by:
Hi, I'm learning to use the Datagridview; I would like sort a column of my DGV, but with code, not with user click over the column, how make that?; Mi other question is how search for a especific...
2
by: Rick | last post by:
VS 2005/Pro I'm using a DataGridView in a Windows form and allowing the user to sort the columns by clicking on the header column. Is there some method offered by the grid to return back to...
0
by: Hassan | last post by:
Hi, Im using visual studio 2005,C#2 Framework 2.0 In my program, i have a DataGridView where DataGridView.DataSource equal to a BindingSource.DataSource and this BindingSource.DataSource equalt...
4
by: NvrBst | last post by:
I have a log viewer. I sort the DataGridView by the Time Column and then run a function to set all cell backcolors depending if the cell above is different. This works correctly, however, when...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.