T
T
TohaPerdoha82019-01-13 12:21:39
.NET
TohaPerdoha8, 2019-01-13 12:21:39

How to implement column sorting in C# datagridview by clicking on the header?

Hello. A problem has arisen. It is necessary that by clicking on the column heading, the list items in the datagrid are sorted by this column. They are presented as a List. How can I do that?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Isaev, 2019-01-13
@MaximIs

bool x;
        private void button1_Click(object sender, EventArgs e)
        {
            // сортировка поочерёдно в обе стороны по первому столбцу
            dataGridView1.Sort(dataGridView1.Columns[0], x ? ListSortDirection.Ascending : ListSortDirection.Descending);
            x = !x;
        }

So have you tried it? Yandex search

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question