Sortowanie automatyczne w DataGridView

0

Mam w bazce 2 pola jedno INT drugie VARCHAR , gdy wyswietle wyniki zapytania w datagridview i klikne na naglowek pola sie sortują ale sortują sie jak dane tekstowe, mam np 1, 15, 34, 123, 256, 4 wynik mam taki:

1
123
15
256
34
4

Znalazlem w edycji kolumn datagridview , w cell style typ kolumny i tam wybralem zamiast no formatting - numeric ale to nic nie dalo , dalej sortuje tekstowo, jak sobie z tym poradzic ?

Fakt ze typ kolumny jest DataGridViewTextBoxColumn ale nie ma opcji zeby wybrac numeryczne tylko sa:
DataGridViewTextBoxColumn, DataGridViewImageBoxColumn, DataGridViewComboBoxBoxColumn itd..

0
msdn napisał(a)

DataGridView.Sort Method
...

This method allows advanced customization of the sorting feature of the DataGridView class. In order to implement a highly customized sorting operation, you can write an event handler for the ColumnHeaderMouseClick event and call this method with an instance of a class that implements the System.Collections.IComparer interface as a parameter. In this case, you will typically set the DataGridViewColumn.SortMode property to DataGridViewColumnSortMode.Programmatic to disable automatic sorting and to leave room for a sorting glyph. When sorting by columns set to programmatic sort mode, you must display the sorting glyph yourself by setting the DataGridViewColumnHeaderCell.SortGlyphDirection property.

This method works only when the DataSource property is not set. When you bind the DataGridView control to an external data source, you must use the sorting operations provided by that data source. When you provide your own data source by implementing virtual mode, you must also handle the sorting operations yourself.

Calling this method automatically sets the CurrentCell property to a null reference (Nothing in Visual Basic).

0

A tak streszczajac?

0

Tak streszczajac to musisz przeladowac zdarzenie ColumnHeaderMouseClick, w ktorym sam uruchomisz metode Sort podajac jej przy okazji obiekt implementujacy IComparer (czyli mowiacy jak i co ma sobie porownac). Ale jeszcze pytanie - wartosci pakujesz do gridview sam, czy poprzez DataSource? Bo jak to drugie, to musisz sobie sortnac w zapytaniu do bazy.

0

Jak wyprowadzić takie zapytanie z vb.net? Dane z Accessa umieszczam w DataGridView w kodzie poprzez DataSource.

EDIT: Ok, dodałem zapytanie i już sortuje :)

1 użytkowników online, w tym zalogowanych: 0, gości: 1