none
DataGridView Behavior RRS feed

  • Question

  • Hi:

    I have several dgvs in an app that I am working on. With some of them you have to arrow down twice

    to move to the second row while others only require one arrow down. The properties are set the same

    way for all dgvs. I can't figure out why this happens. Here are the settings that I am using, all others

    have default values.


                .DefaultCellStyle.BackColor = Color.Cyan
                .DefaultCellStyle.ForeColor = Color.Black
                .DefaultCellStyle.SelectionBackColor = Color.LightSkyBlue
                .DefaultCellStyle.SelectionForeColor = Color.Black
                .ReadOnly = True
                .ScrollBars = ScrollBars.Vertical
                .SelectionMode = DataGridViewSelectionMode.RowHeaderSelect

    Does anyone have any suggestions? Thanks.

    Tuesday, June 16, 2020 1:54 PM

All replies

  • Given what you have presented, there is no reason for this, it must be in your code. 

    • Look at any events for the DataGridView and comment them out, does that help?
    • Try removing the scrollbar code.

    Please remember to mark the replies as answers if they help and unmarked 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.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Tuesday, June 16, 2020 3:06 PM
    Moderator
  • Hi:

    I removed the scrollbar code and the problem persists. There are no events for the dgv.

    The only code is a datareader and and a bindingsource. All of the dgvs have the same

    code the only difference is the number of columns and the table that they are bound to.

    The dgvs that are working correctly seem to be those with only one or two columns.

    Tuesday, June 16, 2020 3:49 PM
  • Hi:

    I removed the scrollbar code and the problem persists. There are no events for the dgv.

    The only code is a datareader and and a bindingsource. All of the dgvs have the same

    code the only difference is the number of columns and the table that they are bound to.

    The dgvs that are working correctly seem to be those with only one or two columns.

    Yea that is what I was thinking of, probably it are datagridviews with very much data, then they become slow. 

    Try to click once and than wait a time. 


    Success
    Cor

    Tuesday, June 16, 2020 5:30 PM
  • Currently there are only a few rows of data and up to four columns as I am in the testing phase.

    Tuesday, June 16, 2020 5:53 PM
  • Currently there are only a few rows of data and up to four columns as I am in the testing phase.

    I tried your code, not any problem at all

      Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            With DataGridView1
                .DefaultCellStyle.BackColor = Color.Cyan
                .DefaultCellStyle.ForeColor = Color.Black
                .DefaultCellStyle.SelectionBackColor = Color.LightSkyBlue
                .DefaultCellStyle.SelectionForeColor = Color.Black
                .ReadOnly = True
                .ScrollBars = ScrollBars.Vertical
                .SelectionMode = DataGridViewSelectionMode.RowHeaderSelect
            End With
            For i = 0 To 4
                DataGridView1.Rows.Add({i, i * 2, i * 3, i * 4})
            Next
        End Sub


    Success
    Cor

    Tuesday, June 16, 2020 6:25 PM
  • Like I said one or two columns is fine but any more than that and there is a problem.
    Tuesday, June 16, 2020 6:30 PM
  • In regards to a DataReader and BindingSource, there is something in between e.g. a DataTable for instance set to the DataSource of the BindingSource, is that the case here? 

    Also


    Please remember to mark the replies as answers if they help and unmarked 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.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Tuesday, June 16, 2020 6:55 PM
    Moderator
  • Like I said one or two columns is fine but any more than that and there is a problem.

    Therfore I used 4 columns and four rows. Did you try it by the way.

    That is less work I did, the only thing what you've to do is make a new project, drag a datagridview, add 4 columns and past my code in the load event. 


    Success
    Cor

    Tuesday, June 16, 2020 7:26 PM