Results 1 to 3 of 3

Thread: [RESOLVED] scan datagridview

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2021
    Posts
    3

    Resolved [RESOLVED] scan datagridview

    hello all,

    I used quite new to visual basic so I'm hoping this is an easy solution. I have a datagridview with multiple columns. One is category and one is amount. What I am trying to achieve, is when the user clicks the button to delete a row, it will scan or find the category and delete the amount of the category for the selected row (to be deleted). I am using windows forms, visual studio 2019

    Hopefully that helps! I can add more info if needed.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,344

    Re: scan datagridview

    Quote Originally Posted by bschlamp83 View Post
    it will [...] delete the amount of the category for the selected row
    What does that even mean? I'm guessing that you mean that you want to subtract that amount from some total stored elsewhere but we shouldn't have to guess. Please provide ALL the relevant information.

    That said, if you aren't already, you should have your data in a DataTable and have bound that to the grid via a BindingSource. Deleting the current row is then a matter of calling RemoveCurrent on the BindingSource. If you want to get the data in the current row before deleting then you can do so using the Current property of the BindingSource, e.g.
    vb.net Code:
    1. Dim currentRow = DirectCast(myBindingSource.Current, DataRowView)
    2. Dim amount = CInt(currentRow("Amount"))
    You can then do whatever you want with that Integer value.

    Note that the BindingSource should be added to the form in the designer.

  3. #3

    Thread Starter
    New Member
    Join Date
    Aug 2021
    Posts
    3

    Re: scan datagridview

    That was what I was asking. Sorry about the confusion. I am still new to this. However thank you for your help!

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