1 Replies - 375 Views - Last Post: 27 July 2019 - 07:06 AM Rate Topic: -----

#1 xiwen_99   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 21-July 19

I wanted to sum the total from the datagridview then display at txtbox

Posted 27 July 2019 - 06:40 AM

I wanted to sum the number from the datagridview and display it at textbox but error
The error message shows: 'Rows cannot be programmatically added to the DataGridView's rows collection when the control is data-bound.'



Private Sub Cart_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the 'FoodorderDataSet1.Foodorder' table. You can move, or remove it, as needed.
        Me.FoodorderTableAdapter.Fill(Me.FoodorderDataSet1.Foodorder)
        con.ConnectionString = "Provider=Microsoft.jet.oledb.4.0;data source=Foodorder.mdb"
        con.Open()
        For i As Integer = 0 To 11 Step +1
            DataGridView1.Rows.Add("Type" + i.ToString(), "Foodname" + i.ToString(), "Quantity" + i.ToString)//This is the error coding//
        Next
        DataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnMode.Fill
        DataGridView1.AllowUserToAddRows = False

        TxtBoxTotal.Text = (From rows As DataGridView In DataGridView1.Rows
                            Where rows.SelectedCells(4).FormattedValue.ToString() <> String.Empty
                            Select Convert.ToInt32(rows.SelectedCells(4).FormattedValue)).Sum().ToString()

    End Sub



Is This A Good Question/Topic? 0
  • +

Replies To: I wanted to sum the total from the datagridview then display at txtbox

#2 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15262
  • View blog
  • Posts: 61,157
  • Joined: 12-June 08

Re: I wanted to sum the total from the datagridview then display at txtbox

Posted 27 July 2019 - 07:06 AM

You would add rows to the dataset that backs the grid.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1