1 Replies - 743 Views - Last Post: 03 September 2013 - 07:27 AM Rate Topic: -----

#1 raelkun00  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 69
  • Joined: 01-October 12

Change cell value of datagridview selectedrow

Posted 03 September 2013 - 06:54 AM

The value is changing my datagridview but I am having this error. I don't know what's wrong.

This is my code in changing the value of datagridview
  Private Sub Button1_Click_1(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        Try
            Dim askprice = InputBox("enter price")
            Dim dr As New DataGridViewRow
            For Each dr In dgvOrders.SelectedRows
                dr.Cells(5).Value = Int32.Parse(askprice)
            Next
        Catch ex As Exception
            MessageBox.Show(ex.ToString)
        End Try
       
    End Sub



This is my code in datagridview cell value changed.Which is also giving error.
 Dim dr As New DataGridViewRow
        For Each dr In dgvOrders.SelectedRows
            If dr.Cells(6).Value = "" Then
                MessageBox.Show("Quantity cannot be empty", "MLACS", MessageBoxButtons.OK, MessageBoxIcon.Error)
                dr.Cells(6).Value = "1"
            End If
        Next

        If dgvOrders.Rows.Count > 0 Then
            percentDiscount()
            txtSubTotal.Text = subTotal().ToString("C")
            txtSalesTax.Text = getTax().ToString("C")
            txtTotal.Text = TotalSales().ToString("C")
        End If



This is my error.
Posted Image

Is This A Good Question/Topic? 0
  • +

Replies To: Change cell value of datagridview selectedrow

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9096
  • View blog
  • Posts: 34,161
  • Joined: 12-June 08

Re: Change cell value of datagridview selectedrow

Posted 03 September 2013 - 07:27 AM

The error is pretty self explanatory. You are trying to convert an empty string into a number. If you are not going to check for empty values I would suggest using 'TryParse' instead of just 'Parse'.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1