locked
DGV - How can I allow the user to close specific columns of the DGV ? RRS feed

  • Question

  • Hi ,

          1.  How can I allow the user to close specific columns of the DGV 

               (and optionaly reopen them ) 

           2. When I set the property "AllowUserToOrderColumns" to true :

                                     myDGV1.AllowUserToOrderColumns = true; 

                How does to user reorders the columns ? (I did not find the way , as a user )

     


    good morning sunshine
    Monday, June 6, 2011 4:36 PM

Answers

All replies

  • You can set the columns as .visible = true

    You can always loop through the columns and set the property. Here's some pseudo

    for each col as datagridviewcolumn in my dgv.columns

    if col.Name = txtColToHide.text then

    col.visible = false

    Adam


    Ctrl+Z
    Monday, June 6, 2011 4:47 PM
  • Thanks

    I know that

    My question is : How can I allow the user to close specific columns of the DGV on his choice

     

     


    good morning sunshine
    Monday, June 6, 2011 5:13 PM
  • What do you mean by "close"? And how do you intend to allow user that?

    Please explain better.

    IN ADDITION: Hiding column is the only way to dissapearing of the column, but there is something else; this is Disabling column. Do you mean to disable it? Not let the user to use it?

     


    Mitja

    Monday, June 6, 2011 5:16 PM
  • Thanks

    I know that

    My question is : How can I allow the user to close specific columns of the DGV on his choice

     

     


    good morning sunshine


    you can use a ContextMenu component to show two items:"Hide Column", "Show Column", and set the DataGridView's ContextMenuStrip to the ContextMenu, and then in the hideColumnToolStripMenuItem's Click event to hide the column by setting the column's visible to false.

    Also this link has target at the similar topics which would be much helpful: http://social.msdn.microsoft.com/Forums/en/winformsdatacontrols/thread/66abf9e4-fec9-4cae-818e-9a4b547320c9 


    Helen Zhou [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.


    • Marked as answer by Helen Zhou Thursday, June 30, 2011 8:03 AM
    Wednesday, June 15, 2011 2:17 AM
  • Hello gilit2,

    How's the issue going on? Was my reply give some help? If you it didn't help, please explain more clearly about the question and update the thread.


    Helen Zhou [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.


    Tuesday, June 21, 2011 2:52 AM