Results 1 to 9 of 9

Thread: [RESOLVED] Selection From a DataGrid.

  1. #1

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

    Resolved [RESOLVED] Selection From a DataGrid.

    I have a datagrid in which I want to double click on a specific Access record (any cell in the row) and from there open a form that displays the data for that specific record. The subroutine is setup as a double click event for tblFileMasterBaseDataGridView on any cell in the datagrid.
    When this event is executed it opens a form as expected. However, I cannot figure out how to open the form to display the specific record selected with the double click. Can anyone describe to me what it is I need to do? Can this even be done?

    I have attached the subroutine (with my latest non-working attempt) and the datagrid that I am using to call the form (not in there yet). Sorry that I cannot describe this better, but I have moved way beyond my pay grade on this one.
    Attached Images Attached Images   

  2. #2
    Hyperactive Member
    Join Date
    Sep 2014
    Posts
    404

    Re: Selection From a DataGrid.

    to get the selected file ID you need to handle either the cell click or cell content click event

    then you can access the e.ColumnIndex and e.RowIndex
    using these values you can obtain the file ID as follows replacing 'MyDataGridView' with the name of your datagrid and the 'MyColumnName' with either the number 0 or the column name of your file ID

    Code:
    Me.MyDataGridView.Rows(e.RowIndex).Cells("MyColumnName").Value.ToString

  3. #3

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

    Re: Selection From a DataGrid.

    It almost worked. However, I get an unhandled exception error on that line telling me that the column cannot be found. And I did use the column in my table not what you put above.

  4. #4
    Hyperactive Member
    Join Date
    Sep 2014
    Posts
    404

    Re: Selection From a DataGrid.

    change to the position of the column, in the image this would be 0 without the speech marks
    Last edited by Leary222; Feb 25th, 2015 at 05:53 PM. Reason: clarity

  5. #5

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

    Re: Selection From a DataGrid.

    The form opens, but always displays the first record.

  6. #6

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

    Re: Selection From a DataGrid.

    Actually, it is selecting the column value I want (I put the code into a message box). However, it seems to lose the index when I open the form for that record. Obviously there is something more I need. I have an idea that I am going to try, but let me know if you already know what I am still missing.

  7. #7
    Hyperactive Member
    Join Date
    Sep 2014
    Posts
    404

    Re: Selection From a DataGrid.

    from my understanding of the solution you are looking for:
    you want a user to be able to click on a record and for that record to open from the code I have shown you, you should be able to obtain the ID number of the record clicked on and then open the form.

    in order to pass that value to the form you can either set a public variable or pass it as a variable in the forms new event.

    then what you do with that ID to change what is shown on the form is up to you if you need any help on this please explain further

  8. #8

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

    Re: Selection From a DataGrid.

    Well that is embarrassing. I forgot that I need to carry the value into the call for the form. And yes, that did give me what I needed, I just seem to have forgotten what I needed.

  9. #9
    Hyperactive Member
    Join Date
    Sep 2014
    Posts
    404

    Re: [RESOLVED] Selection From a DataGrid.

    no problems hope I have been of help

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