Results 1 to 8 of 8

Thread: [RESOLVED] Datagridview overloading, I think.

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2011
    Location
    Oregon City, Oregon
    Posts
    705

    Resolved [RESOLVED] Datagridview overloading, I think.

    I am working with a datagridview and am having a problem with the way I am using it.



    When the DGV is displayed in the form, the Upper left corner cell of the DGV is the focus. I would like for there to be no cell in the DGV focused.

    The reason this is a problem is that I am using the DGV_CellDoubleClick() event.

    The Adding and Editing properties are set to true for the DGV, as I want to be able to edit some of the data without opening the record form.

    What occurs, is that if I double click in the focused cell, the application crashes. I have not spent any significant time trying to figure out why this occurs, as the problem would go away if there is no cell in the DGV that is in focus.

  2. #2
    PowerPoster
    Join Date
    Sep 2005
    Location
    Modesto, Ca.
    Posts
    5,508

    Re: Datagridview overloading, I think.

    What occurs, is that if I double click in the focused cell, the application crashes. I have not spent any significant time trying to figure out why this occurs, as the problem would go away if there is no cell in the DGV that is in focus.
    I don't understand. A user can double click on on any dgv cell whether it has focus or not.

    To answer your question, if you don't want a dgv cell selected then set "yourDataGridView.CurrentCell = Nothing"
    Last edited by wes4dbt; Jun 21st, 2023 at 02:44 PM.

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2011
    Location
    Oregon City, Oregon
    Posts
    705

    Re: Datagridview overloading, I think.

    I believe that as well, which is why I setup the DGV with the double Click Event. However, that is not the case. Whatever cell has focus in the DGV, if double clicked, will crash the program. I get a System.NullReferenceException message stateing that, "Object reference not set to an instance of the object".

    I am guessing that it has something to do with the fact that I have the properties of the DGV set for me to be able to edit the cells. But I am sure that if no cell had focus I would not see this problem.

    This is the event that I am using.

    Code:
        Private Sub dgvTask_CellDoubleClick(sender As Object, e As DataGridViewCellEventArgs) Handles dgvList.CellDoubleClick
            If e.RowIndex < 0 Or e.ColumnIndex < 0 Then Exit Sub
            'Define variables and extract from query.
            MyName = CStr(Me.dgvList.Rows(e.RowIndex).Cells(0).Value.ToString)
            TaskOwner = CStr(Me.dgvList.Rows(e.RowIndex).Cells(1).Value.ToString)
            TaskStart = CStr(Me.dgvList.Rows(e.RowIndex).Cells(2).Value.ToString)
            TaskEnd = CStr(Me.dgvList.Rows(e.RowIndex).Cells(3).Value.ToString)
            PercentComplete = CDec(Me.dgvList.Rows(e.RowIndex).Cells(4).Value.ToString)
            CheckRec = CStr(Me.dgvList.Rows(e.RowIndex).Cells(5).Value.ToString)
            Me.Hide()
            taskRecord.Show()
        End Sub

  4. #4
    PowerPoster
    Join Date
    Sep 2005
    Location
    Modesto, Ca.
    Posts
    5,508

    Re: Datagridview overloading, I think.

    I gave you the answer in the first post. I must have added that while you were posting.

  5. #5
    PowerPoster
    Join Date
    Nov 2017
    Posts
    3,630

    Re: Datagridview overloading, I think.

    It's a moot point as far as the issue is concerned, but for your own benefit (and for others reading your code) you should probably rename that method to match the (presumably renamed at some point) DGV name:

    Code:
    Private Sub dgvTask_CellDoubleClick(sender As Object, e As DataGridViewCellEventArgs) Handles dgvList.CellDoubleClick

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2011
    Location
    Oregon City, Oregon
    Posts
    705

    Re: Datagridview overloading, I think.

    I gave you the answer in the first post.
    I guess I missed it. Having said that, I did that in my DGV settings code, with the same outcome. Additionally, most, if not all of the cells in the DGV are filled, so wouldn't that eliminate any value already in the cell?

    you should probably rename that method to match...
    Done

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2011
    Location
    Oregon City, Oregon
    Posts
    705

    Re: Datagridview overloading, I think.

    I was wrong. That did fix it. It turns out that there was more than one place that needed that particular statement. That resolves my issue.

    However, I would still like to understand why the error occurs in the first place. I just cannot understand why a cell that is focused, if you will, would have a conflict of any nature with the event that I have.

  8. #8
    PowerPoster
    Join Date
    Sep 2005
    Location
    Modesto, Ca.
    Posts
    5,508

    Re: [RESOLVED] Datagridview overloading, I think.

    I have no idea why setting the dgv currentcell property to nothing would effect the code. But, I also don't have any idea what line is causing the error or the other place you needed to set the currentcell property.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width