Select multiple rows from DataGridView and save them to DataTable
Hello, I have a DataGridView that contains several rows. Say, I select 5 rows from it, click a "Save" button, but only the 5 rows I selected are going to be saved to the DataTable.
I already know how to activate the property to multiselect the rows. The problem is I don't know know to save the selected rows to the DataTable (with only a selected row I have no issue).
Is there an example at CodeBank? Or any idea on how to achieve this?
Thank you.
Re: Select multiple rows from DataGridView and save them to DataTable
Maybe something like this (unless, of course, I'm misunderstanding the question):
vb Code:
For Each row As DataGridViewRow In Me.DataGridView1.Rows
If row.Selected Then
'add a row to the datatable
End If
Next
But now, how exactly is the data getting into the DataGridView in the first place?
Re: Select multiple rows from DataGridView and save them to DataTable
Quote:
Originally Posted by
dolot
Maybe something like this (unless, of course, I'm misunderstanding the question):
vb Code:
For Each row As DataGridViewRow In Me.DataGridView1.Rows
If row.Selected Then
'add a row to the datatable
End If
Next
But now, how exactly is the data getting into the DataGridView in the first place?
Thank you, I'll give it a try.
PS: The data is getting into the DataGridView from a SQL table called "Menu" (the kind of menu you have at the restaurant). So, if a client orders, they are not going to order only one meal or only one drink; they are going to order multiple drinks, meals, desserts, appetizers,... at once (specially if it's not only a client, but a romantic couple or two or more friends sharing a table). And the restaurant manager or employee is not going to like to add everything the client ordered, one by one; neither the clients are going to like having to wait extra time. Then, I'll add a new column to the DataGridView: "Cantity"; if the row is selected, but cantity is null, then it won't be saved.
The selected rows and cantity will be stored on the DataTable, which it turn will be saved to a "Order" table.