473,406 Members | 2,345 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

DataGridView - Insert Row

how do you insert a new row to a databound datagridview? It won't allow this
action.
Apr 2 '07 #1
4 39724
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Nodir Gulyamov | last post by:
Hello All, First of all thanks in advance to everyone who will try to help me. I have Form with TreeView control and DataGridView control. Each TreeNode has its own rows and due to I am placing...
10
by: Henok Girma | last post by:
Hello Gurus, I want to save the state of an unbound DataGridView on my Windows Form application to an XML file so i can later load it back.. Basically, on my form I have a DataGridView, it's got...
0
by: Dave | last post by:
I have a table with 3 fields of which the primary key is a autonumber. I have created my dataadapter, dataset and datagridview using a wizard. However, in the datagrid, the update and delete...
1
by: Dave | last post by:
I have a table with 3 fields of which the primary key is a autonumber. I have created my dataadapter, dataset and datagridview using a wizard. However, in the datagrid, the update and delete...
3
by: Rich | last post by:
Hello, I am populating a datagridview from a datatable and filtering the number of rows with a dataview object. Is there a way to retrieve the rows displayed by the datagridview into a separate...
2
by: Marc Solé | last post by:
Hello, I want to insert an image to a specific column of a dataGridWiew. I explain what I'm doing: - I define the ColumnType as a DataGridViewImageColumn. - I select the image (an icon of...
4
by: =?Utf-8?B?UmljaA==?= | last post by:
On a form - I have a datagridview which is docked to the entire form. The datagridview allows users to Delete and/or Add Rows. On the Form_Load event I Fill the datagridview source table with a...
0
by: Andrus | last post by:
I tried to edit data in DataGridView. Insert and delete operations in grid are not saved to database. Updating works OK. How to force grid to save Insert and Delete operations also ? Andrus....
0
by: KA NMC | last post by:
I have a table and a view. My view pulls all new items which needs to be updated and my table has all the new items that already has been updated. What I'm trying to do in a windows application...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.