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

DataGridView - Insert Row

P: n/a
how do you insert a new row to a databound datagridview? It won't allow this
action.
Apr 2 '07 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Chris,

Can you show an example? What is it databound to? Is the
AllowUserToAddRows property set to true on the DataGridView? Or are you
getting an error when trying to do this programattically?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Chris" <Ch***@discussions.microsoft.comwrote in message
news:2F**********************************@microsof t.com...
how do you insert a new row to a databound datagridview? It won't allow
this
action.


Apr 2 '07 #2

P: n/a
AllowUserToAddRows = true
I am trying to add them programatically.
I see an error that you cannot when the datagridview is bound to a dataset.
If the edit a row, then a new row appears automatically at the last row.

I need to "insert" a row before or after a selected row then add data to it.
"Nicholas Paldino [.NET/C# MVP]" wrote:
Chris,

Can you show an example? What is it databound to? Is the
AllowUserToAddRows property set to true on the DataGridView? Or are you
getting an error when trying to do this programattically?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Chris" <Ch***@discussions.microsoft.comwrote in message
news:2F**********************************@microsof t.com...
how do you insert a new row to a databound datagridview? It won't allow
this
action.


Apr 2 '07 #3

P: n/a
Try adding a row to the DataTable, and not the DataGridView

Try something like:

DataRow myNewRow;
myNewRow = myDataSet.myDataTable.NewRow(); // assuming typed dataset
myNewRow[0] = ...
myDataSet.myDataTable.Rows.Add(myNewRow);

"Chris" wrote:
AllowUserToAddRows = true
I am trying to add them programatically.
I see an error that you cannot when the datagridview is bound to a dataset.
If the edit a row, then a new row appears automatically at the last row.

I need to "insert" a row before or after a selected row then add data to it.
"Nicholas Paldino [.NET/C# MVP]" wrote:
Chris,

Can you show an example? What is it databound to? Is the
AllowUserToAddRows property set to true on the DataGridView? Or are you
getting an error when trying to do this programattically?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Chris" <Ch***@discussions.microsoft.comwrote in message
news:2F**********************************@microsof t.com...
how do you insert a new row to a databound datagridview? It won't allow
this
action.
>
>
Apr 3 '07 #4

P: n/a
Forgot too... when you add a row, it adds to the end.

Do you have a column that you can use for an index or sort on? I'd say if
there is, you may be able to add the row, set the key column, and then
refresh the datagridview? To borrow a very old method used in the old days
of BASIC...

you could have each row with a column having a sequence number, say 10, 20,
30, 40... and when you add a row, you could insert a row say at 15. You may
have to "re-align" the rows on the fly if you start adding a lot of rows
however.

I haven't tried it, but this almost seems like a task for a Doubly-Linked
list.

"SerenityPCCS" wrote:
Try adding a row to the DataTable, and not the DataGridView

Try something like:

DataRow myNewRow;
myNewRow = myDataSet.myDataTable.NewRow(); // assuming typed dataset
myNewRow[0] = ...
myDataSet.myDataTable.Rows.Add(myNewRow);

"Chris" wrote:
AllowUserToAddRows = true
I am trying to add them programatically.
I see an error that you cannot when the datagridview is bound to a dataset.
If the edit a row, then a new row appears automatically at the last row.

I need to "insert" a row before or after a selected row then add data to it.
"Nicholas Paldino [.NET/C# MVP]" wrote:
Chris,
>
Can you show an example? What is it databound to? Is the
AllowUserToAddRows property set to true on the DataGridView? Or are you
getting an error when trying to do this programattically?
>
>
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
>
"Chris" <Ch***@discussions.microsoft.comwrote in message
news:2F**********************************@microsof t.com...
how do you insert a new row to a databound datagridview? It won't allow
this
action.


>
>
>
Apr 3 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.