Visual Studio Developer Center > Visual Studio Forums > Visual Studio Class Designer > how to prevent other people from sorting my DataGridView??
Ask a questionAsk a question
 

Answerhow to prevent other people from sorting my DataGridView??

Answers

  • Friday, October 30, 2009 10:27 AMYiChun ChenMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     AnswerHas Code

    Hi Buz_88,

    Welcome to MSDN forums.

    To disable the sorting function of one DataGridView, please try the following code snippet:

    Dim i As Integer
    
    For i = 0 To DataGridView1.Columns.Count - 1
    
        DataGridView1.Columns.Item(i).SortMode = DataGridViewColumnSortMode.Programmatic
    
    Next i
    

    or

        Dim i As DataGridViewColumn
        For Each i In dataGridView1.Columns
            i.SortMode = DataGridViewColumnSortMode.NotSortable
        Next i
    
    

    Hope this helps. If you have any concern, please feel free to let me know.

    Best regards,
    Yichun Chen
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.

All Replies

  • Friday, October 30, 2009 10:27 AMYiChun ChenMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     AnswerHas Code

    Hi Buz_88,

    Welcome to MSDN forums.

    To disable the sorting function of one DataGridView, please try the following code snippet:

    Dim i As Integer
    
    For i = 0 To DataGridView1.Columns.Count - 1
    
        DataGridView1.Columns.Item(i).SortMode = DataGridViewColumnSortMode.Programmatic
    
    Next i
    

    or

        Dim i As DataGridViewColumn
        For Each i In dataGridView1.Columns
            i.SortMode = DataGridViewColumnSortMode.NotSortable
        Next i
    
    

    Hope this helps. If you have any concern, please feel free to let me know.

    Best regards,
    Yichun Chen
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
  • Monday, November 02, 2009 4:24 AMbuz_88 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    thanks.. it works!!
  • Monday, November 02, 2009 4:40 AMYiChun ChenMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi Buz_88,

    It's my pleasure! :)

    Have a great week.

    Best regards,
    Yichun Chen
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.