?
Solved

Visual Studio 2005 DataGridView - Delete row of cells programatically

Posted on 2006-06-01
5
Medium Priority
?
2,368 Views
Last Modified: 2011-09-20
Hi

I am able to add rows programatically in my DataGridView, but cannot
find out how to delete them.

Thanks

0
Comment
Question by:Murray Brown
  • 3
  • 2
5 Comments
 
LVL 12

Expert Comment

by:vb_jonas
ID: 16805818
You have to work with the DataTable behind the grid, and from there delete the row.

MyDataTable.Select("ID=" & DeleteFirstRowWithThisID)(0).Delete



0
 

Author Comment

by:Murray Brown
ID: 16805834
Hi
Thanks
I am not quite sure what you mean by ID. Please would you give me an example.
My DataGridView is simply called DGV and I want to delete line 50
0
 
LVL 12

Expert Comment

by:vb_jonas
ID: 16805921
I missed - the datagridview has a rows.remove - method. So in your case, this works:

        dgv.Rows.Remove(dgv.Rows(50))


You should also update the adapter to remove the row from the database. Like you do in your add row - routine. Ok?

0
 
LVL 12

Accepted Solution

by:
vb_jonas earned 2000 total points
ID: 16805926
remember row counting starts with 0, so maybe it is row number 49 you like to remove :-)
0
 

Author Comment

by:Murray Brown
ID: 16805977
Great thanks very much for that :-)
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
How can you see what you are working on when you want to see it while you to save a copy? Add a "Save As" icon to the Quick Access Toolbar, or QAT. That way, when you save a copy of a query, form, report, or other object you are modifying, you…
How to fix display issue, screen flickering issue when I plug in power cord to the machine. Before I start explaining the solution lets check out once the issue how it looks like after I connect the power cord. most of you also have faced this…
Suggested Courses

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question