Datagridview cell content deselect

I have a question regarding the Datagridview control. When I use mouse to select one cell, the value of this cell will be selected automatically, but I would prefer it not being selected, just put the cursor at the end of the value. How can i do that

Thanks


Answer this question

Datagridview cell content deselect

  • Anudeep_Chappa_2dc7df

    Thanks for your help,Renee. i will try to show the effect some other time, as it is not that important in the project.

  • Marcos Dell Antonio de Souza

    I did try in a new project by populating the control with some data, and put your codes accordingly (and set the Multiselect to fault in property window as well as in program), but does not work either. The 'Edit Mode' has been set to 'Edit on Enter', and 'Selection Mode' has been set to 'CellSelect'. not sure what other setting needed to be reset



  • progames25

    It worked perfecctly here. Do you have the Heedselect logic every where.

    Did you try that in a new project Also did you set the properties like Multiselect



  • robhare

     

    I didn't set any of those. Whatever I set is set in code.   Try unsetting the things you set, like edit on enter etc and then see if the de-select works>

    Btw it's "code"  it's never "codes". 



  • cheston

    OK :)

  • xxfredxx

    Hi, Renee

    Thanks for the reply. I tried your code, but somehow it is not working as expected. The content in the cell is still selected when clicking the cell, and the assignment of "false" is always not successfully executed. Not sure why.

    DGV1.SelectedCells(0).Selected = False


  • cooldoger

     

    Imports System.Data

    Imports System.Data.OleDb

    Public Class Form1

     

        Private HeedSelect As Boolean

        Private Sub Form1_Load(ByVal sender As Object, _

                  ByVal e As System.EventArgs) Handles Me.Load

            con.Open()

            DGV1.MultiSelect = False

            DGV1.DataSource = adodb.GetTable("Categories")

            HeedSelect = True

        End Sub

        Private Sub DGV1_SelectionChanged(ByVal sender As Object, _

              ByVal e As System.EventArgs) Handles DGV1.SelectionChanged

            If Not HeedSelect Then Exit Sub

            If DGV1.SelectedCells.Count <> 0 Then
                DGV1.SelectedCells(0).Selected = False

            End If

        End Sub

     

    End Class

     



  • Mark Rendle

     

    OK.  It was the EditonEntry property setting. 

    NEVER change control properties and then tell a developer their code doesn't work. Normally, I include all properties settings in my code like I did with Multiselect.

    Of course select is going to be on with the EditonEntry. EditOnEntry reselects on entry.

    This question is answered and I recognize that there is more information that you need but this question has been answered.

    I think to get the effect you want, you have to use the cellbeginedit and cellendedit. I also don't think you will like the effect you want. Microsoft control in XP, keep the item selected when editing.

     



  • Datagridview cell content deselect