#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2004
    Posts
    194
    Rep Power
    329

    Sorting multiple datagridview columns


    I want to sort multiple datagridview columns programmatically, I used following code...
    Code:
    Me.DataGridView1.Sort(IDDataGridViewTextBoxColumn, ComponentModel.ListSortDirection.Ascending)
    Me.DataGridView1.Sort(CodeDataGridViewTextBoxColumn, ComponentModel.ListSortDirection.Ascending)
    Me.DataGridView1.Sort(BlnoDataGridViewTextBoxColumn, ComponentModel.ListSortDirection.Ascending)
    but it doesn't quite work, one of the column looses its order. Is there a way to force multiple columns to certain order and/or set one or more columns more dominant?
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2011
    Posts
    119
    Rep Power
    0

    Sorting multiple datagridview columns


    Hi
    Find the reply of your question...

    If your DataGridView is databound, you can sort your Datatable view and rebind to datagridview as below (Code in C#):

    DataView view = Datatable.DefaultView;
    view.Sort = "ID ASC, status DESC";
    dataGridView.DataSource = view; //rebind the data source

    Thanks & Regards
    Diya

IMN logo majestic logo threadwatch logo seochat tools logo