Update selected row in datagridview-VBForums
Results 1 to 3 of 3

Thread: Update selected row in datagridview

  1. #1

    Thread Starter
    Member
    Join Date
    Sep 2007
    Posts
    35

    Update selected row in datagridview

    I want to have a button onces clicked up date a selected row field in my datagridview to either check a checkbox or set the field to lets say complete.

    I tried using the following but I get a error. ( I am totally guessing here on this line of code! I bet that is why it does work LOL.)
    Kb_cartDataGridView.CurrentRow.Selected = "status='" & True & "'"

    Error:
    Conversion from string "status='True'" to type 'Boolean' is not valid.

    Thanks

    Richard

  2. #2

    Thread Starter
    Member
    Join Date
    Sep 2007
    Posts
    35

    Re: Update selected row in datagridview

    Okay I figured out that:
    Kb_cartDataGridView.CurrentRow.Selected = "status='" & True & "'"

    Is not what I wanted... as it seems this code is to select the entire row.. and I had it wrote wrong.
    Kb_cartDataGridView.CurrentRow.Selected = True

    So now I have the whole row highlighted how do I update complete field to completed?

  3. #3
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    87,829

    Re: Update selected row in datagridview

    The MSDN documentation says of the DataGridViewRow.Selected property:
    Gets or sets a value indicating whether the row is selected.
    Is that actually what you want to do, set whether the row is selected or not? Obviously not, as you say that you want to set the value of a field in that row.

    A quick look at the MSDN help topic for the DataGridViewRow member listing shows the Cells property, described thusly:
    Gets the collection of cells that populate the row.
    Hmmm... that sounds like it might be useful, given that you want to set the value of a cell in that row.

    Clicking on the property name, which is a link, takes us to the Help topic for that property. It has an Example section that says this:
    The following code example uses the Cells property to set the value of a cell in the row. This code example is part of a larger code example provided in How to: Manipulate Rows in the Windows Forms DataGridView Control.
    and provides this code example:
    Code:
    ' Give cheescake excellent rating.
    Private Sub Button8_Click(ByVal sender As Object, _
        ByVal e As System.EventArgs) Handles Button8.Click
    
        UpdateStars(dataGridView.Rows(4), "******************")
    End Sub
    
    Private ratingColumn As Integer = 3
    
    Private Sub UpdateStars(ByVal row As DataGridViewRow, _
        ByVal stars As String)
    
        row.Cells(ratingColumn).Value = stars
    
        ' Resize the column width to account for the new value.
        row.DataGridView.AutoResizeColumn(ratingColumn, _
            DataGridViewAutoSizeColumnMode.DisplayedCells)
    
    End Sub
    Who would have thought the Help could be so helpful? Perhaps it could even help someone without a comprehensive understanding of VB to gain that understanding. It might even help them learn things that they weren't even looking for.

    2007-2014

    Why is my data not saved to my database? | MSDN Data Walkthroughs
    MSDN "How Do I?" Videos: VB | C#
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts) | WP8 Turnstile Feather Transition with Pivot Control
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.