-
Jan 6th, 2015, 11:00 AM
#1
Thread Starter
New Member
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.
-
Jan 6th, 2015, 11:32 AM
#2
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?
 I always add to the reputation of those whose post are helpful, and even occasionally to those whose posts aren't helpful but who obviously put forth a valiant effort. That is, when the system will allow it.
My war with a browser-redirect trojan
-
Jan 6th, 2015, 12:43 PM
#3
Thread Starter
New Member
Re: Select multiple rows from DataGridView and save them to DataTable
 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.
Last edited by soulblazer; Jan 6th, 2015 at 01:01 PM.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|