none
DGV Display RRS feed

  • Question

  • I have the following form:

    As you can see there are two DGVs here.  The one on the left is nothing but a DGV for someone to e-sign on and the one on the right is one that appears when the Add Approver button is clicked so that approvers can be added to the left DGV.

    Everything is working as required, but what I do not like is that in both DGVs the first row is highlighted (in the left hand cell).

    I would like there to be NO highlighted cells and have been unable to make that happen.  Can anyone explain to me how this can be achieved?


    gwboolean

    Friday, May 12, 2017 4:38 PM

All replies

  • Do you mean you never want the cell to be highlighted?

    If so try this.

    Private Sub CustomersDataGridView_SelectionChanged(
        sender As Object,
        e As EventArgs) Handles CustomersDataGridView.SelectionChanged
    
        CustomersDataGridView.ClearSelection()
    
    End Sub


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites


    Friday, May 12, 2017 4:48 PM
    Moderator
  • Hi

    If you do not want any sign of the cell/row which is selected then you could change the DefaultCellStyle property of the DGV so that the SelectionBackColor is the same as the BackColor and same for SelectionForeColor/ForeColor.

    In one project, I use this in a DGV which is used for display purposes only. (in my case, I also trap the CellClick and instead of the DGV cell becoming selected, I divert it to a hidden control instead)


    Regards Les, Livingston, Scotland


    • Edited by leshay Friday, May 12, 2017 4:58 PM
    Friday, May 12, 2017 4:52 PM
  • Hi gwboolean,

    The way I've found to "disable" highlighting is to set the SelectionBackColor and the SelectionForeColor in the DefaultCellStyle to the same as the BackColor and ForeColor, respectively.  You could probably do this programmatically on the form's Load event, please refer to the code below.

    Me.DataGridView1.DefaultCellStyle.SelectionBackColor = Me.DataGridView1.DefaultCellStyle.BackColor
            Me.DataGridView1.DefaultCellStyle.SelectionForeColor = Me.DataGridView1.DefaultCellStyle.ForeColor

    Hope it is helpful to you.

    Best Regards,

    Cherry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Monday, May 15, 2017 9:28 AM
    Moderator