If anyone knows how, please, help write such sorting code on the dataGridView column so that everything is adequate with double digits. That is, the values ​​in the cell are always in the format string and when sorting it cannot perceive 10 as "ten", it perceives as "one and zero". I tried to convert the cell into a numeric format via Convert, TryParse, Parse and tipeoff, but to no avail. Is it really so difficult in C #? This is what sorting now looks like:

void SortDataViewByColumn(DataGridView dataGridView, string nameColumn) // Подпрограмма сортировки по интересу { dataGridView.Sort(dataGridView.Columns[nameColumn], ListSortDirection.Descending); } 

And her call when you press the button

  private void сортироватьЧастныеТаблицыToolStripMenuItem_Click(object sender, EventArgs e) { SortDataViewByColumn(dataGridView2, "dataGridViewTextBoxColumn8"); SortDataViewByColumn(dataGridView3, "dataGridViewTextBoxColumn2"); SortDataViewByColumn(dataGridView4, "dataGridViewTextBoxColumn4"); SortDataViewByColumn(dataGridView5, "dataGridViewTextBoxColumn10"); SortDataViewByColumn(dataGridView6, "dataGridViewTextBoxColumn6"); } 

Please, help please, my hands have already dropped - my knowledge of the language is absolutely not enough for this.

1 answer 1

You can work with DataGridView manually, but this is extremely inconvenient. Use the DataSource property to bind the displayed data to the DataGridView , and place the data in a separate collection and sort it as you like by events from the DataGridView or other form elements. A collection with data can be any, but there are some nuances in the behavior of the DataGridView when working with different collections. For a simple display, List<YourDataItems> is enough; if you need the ability to add lines at no extra cost, then it is better to use the BindingList<<YourDataItems> . Well, there is always the option to make a full-format databinding, but this already depends on the task.