By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,960 Members | 2,232 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,960 IT Pros & Developers. It's quick & easy.

Adding rows to a gridview

P: 47
Here's the deal. I have a gridview that I need to fill by adding one record at a time. Is there a procedure for inserting a record in a gridview?
Apr 7 '09 #1
Share this Question
Share on Google+
8 Replies

Expert Mod 5K+
P: 9,731
Add the row to the Object that you are using as the data source for the GridView and it will appear in your GridView.

Apr 7 '09 #2

P: 47
The values of several of the columns are dependent on other columns in the rows so I wanted to evailuate the data defore displaying it in the grid. From what I've read, it's not possible to insert rows into a dataview one by one programically. I'm not sure I understand your solution.
Apr 7 '09 #3

Expert Mod 5K+
P: 9,731
See you never mentioned the use of a DataView so I wasn't exactly sure what you were doing.

To do this you need to dynamically create a DataTable.
Then create a new DataView based on this DataTable:

Expand|Select|Wrap|Line Numbers
  1. Dim dynamicTable As DataTable = createDataTable()
  2. Dim myDataView As New DataView(dynamicTable)
  3. myGridView.DataSource = myDataView;
Apr 7 '09 #4

P: 47
So all my modification will be to the data table then the dataview will just use the data table as a source. Is that correct?
Apr 7 '09 #5

P: 145
It is EXTREMELY pain in everywhere to insert a record using Gridview. Here is a good article yet painful.

I have 10 more links on this. let me know if these dont help. Good Luck
Apr 7 '09 #6

Expert Mod 5K+
P: 9,731
Well once it's in the DataView you can access the table and edit the data there, yes.
Apr 8 '09 #7

P: 47
Is that the way you'd do it?
Apr 8 '09 #8

Expert Mod 5K+
P: 9,731

It's not pretty and I'm sure that there is a more elegant way to do it (using a different Object as the datasource).

But it's not as bad as it sounds. Especially if you are grabbing data from a database because you'll likely already have a table at that point.

In my case I'm converting Objects into a table, so it's a bit messier than your solution will be. Well it's only messy for the table generation part really, after that it's not so bad. It's been a long time since I've used a database (hope that will change in the near future).
Apr 8 '09 #9

Post your reply

Sign in to post your reply or Sign up for a free account.