473,378 Members | 1,417 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,378 software developers and data experts.

Delete one row from Data Grid

On click of the cmdRemove button, I want the selected row in a data grid to
be removed. Here is my attempt, but code generates errors.

private void cmdRemove_Click(object sender, System.EventArgs
e)
{
DataTable dt = dgPrivileges.DataSource as DataTable;
dt.Rows.Remove(dgPrivileges.CurrentRowIndex);
}

Nov 17 '05 #1
2 20159
Mike,

You might want to try the RemoveAt method on the Rows class, as you want
to pass an index. The Remove method takes a data row, not an integer (which
is what the CurrentRowIndex returns).

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Mike L" <Ca***@nospam.nospam> wrote in message
news:06**********************************@microsof t.com...
On click of the cmdRemove button, I want the selected row in a data grid
to
be removed. Here is my attempt, but code generates errors.

private void cmdRemove_Click(object sender,
System.EventArgs
e)
{
DataTable dt = dgPrivileges.DataSource as
DataTable;
dt.Rows.Remove(dgPrivileges.CurrentRowIndex);
}

Nov 17 '05 #2
Nicholas Paldino [.NET/C# MVP] wrote:
Mike,

You might want to try the RemoveAt method on the Rows class, as you want
to pass an index. The Remove method takes a data row, not an integer (which
is what the CurrentRowIndex returns).

Hope this helps.

Yes, but if the user has sorted by clicking a column header, or if the
DataView being used by the grid is ordered (or filtered) differently
from the underlying DataTable, then you'll have trouble.

The best thing to do in this case is to get a reference to the
CurrencyManager for the DataGrid. Try this article:

http://www.codeproject.com/cs/miscct...CurrentRow.asp

HTH,
M.
Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: pmud | last post by:
Hi, I have 4 columns in my sql database table. I added a data adapter , data set & a data grid to view this information. But the data grid is displaying those 4 columns TWICE , i.e in the data...
5
by: pmud | last post by:
Hi, I need to display columns in a data grid based on 7 different queries. Now I have 32 questions: 1. Is it possble to have 1 single data adapter with 7 queries & 1 data set or do I need to...
2
by: Gary | last post by:
Hello All, I have an editable data grid in my web form, this grid allows the user to add new records, edit existing records and also delete them. When a user adds a record the grid goes in to...
2
by: Eric | last post by:
I create form with master detail relation ship. It shows two data grid control. I want to remove one. I want to use one grid control by which i can add delete data in both tables. Thanks,
3
by: kevinpublic | last post by:
I have an item list for ordered products on a data grid in VS 2003. It's an ASP page running VB behind it. All detail lines display as well as all shipping charges. On the edit screen, we allow...
2
by: sandhya20 | last post by:
Hi, I have a Data Grid with some rows...its multiselect property is set to true. in that one column name is "Deletable" takes values (0 or 1)ie 0-means not deletable... 1-deletable . So when i ...
11
by: dongarbage | last post by:
I'm building an application (WPF) and I have a Panel in the application which will be populated dynamically with objects of the type Grid, TextBox, etc. For simplicity, let's say I'm just adding...
0
by: sridharvenkataramanan | last post by:
Hi, I am trying to display a kind of tree like structure with in a data grid. Can any one suggest how to proceed or which control would be apt? top nodes +Cosmetics +Beverages Expanding top...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.