C# .NET - How to delete rows and add rows in grid view

Asked By kavitha varma on 03-Jul-12 04:27 AM
I am developing data grid view in windows forms so that in data grid view i want to add rows and delete rows 
KCH replied to kavitha varma on 03-Jul-12 05:08 AM
Hi kavitha,
you check this link.....it will help you
http://technico.qnownow.com/2012/03/29/how-to-insert-update-delete-rows-in-asp-net-gridview-control/ 
George Eric replied to kavitha varma on 03-Jul-12 05:17 AM
This one is also a helpful examples: see: http://www.java2s.com/Tutorial/CSharp/0460__GUI-Windows-Forms/TableCreateRowDelete.htm 
Keating Megan replied to kavitha varma on 03-Jul-12 05:32 AM
After the reflection, you can see the below code,

public virtual int Add()

{

    if (this.DataGridView.DataSource != null)

    {

      throw new InvalidOperationException(SR.GetString("DataGridViewRowCollection_AddUnboundRow"));

    }

    if (this.DataGridView.NoDimensionChangeAllowed)

    {

      throw new InvalidOperationException(SR.GetString("DataGridView_ForbiddenOperationInEventHandler"));

    }

    return this.AddInternal(false, null);

}


if you set the property of datasource to be data  and when you add rows and columns, an error occurs. So, you need to add binding source and use it to connect the datatable with gridview. Thus, you can realize your task.

people who want to create data grid view can go to this page http://www.e-iceblue.com/Knowledgebase/Spire.PDF/Demos/Grid.html#twoj_fragment1-1 
kavitha varma replied to Keating Megan on 03-Jul-12 06:00 AM
 data grid view event to be rised when i delete the row.so  how can i implement the event and when i selecte the multiple rows to delete
Keating Megan replied to kavitha varma on 05-Jul-12 06:20 AM
I will try,but I am a little busy now.