473,388 Members | 863 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,388 software developers and data experts.

deleting selected rows in a DataGrid

Hi,

with SetDataBinding( ) a DataGrid shows a DataView. user can select some
rows in the grid by holding cotrol key. when user clicks on Delete button, I
should delete all selected rows. I am trying to delete these lines from the
dataview like this:

for (int i=0; i < dataView.Count; i++)
if (dataGrid.IsSelected(i))
dataView.Delete(i);

but after deleting the first line, all other selected rows, become
unselected and I cannot delete the rest of selected rows. how can I ask
DataGrid not to reset the status of rows?

thanks
Nov 16 '05 #1
5 14699
how about desselecting it first before deleting, :p. If that doesn't work,
i'll go for a temporary storage...

"Mojtaba Faridzad" <mf*******@hotmail.com> wrote in message
news:un**************@TK2MSFTNGP15.phx.gbl...
Hi,

with SetDataBinding( ) a DataGrid shows a DataView. user can select some
rows in the grid by holding cotrol key. when user clicks on Delete button, I should delete all selected rows. I am trying to delete these lines from the dataview like this:

for (int i=0; i < dataView.Count; i++)
if (dataGrid.IsSelected(i))
dataView.Delete(i);

but after deleting the first line, all other selected rows, become
unselected and I cannot delete the rest of selected rows. how can I ask
DataGrid not to reset the status of rows?

thanks

Nov 16 '05 #2
Hi,

You can create an ArrayList in which the indexes of the selected rows will
be accumulated. Then, unselect all rows and use the prepared list of indexes
to delete the rows from the data view.

--
Sincerely,
Dmitriy Lapshin [C# / .NET MVP]
Bring the power of unit testing to the VS .NET IDE today!
http://www.x-unity.net/teststudio.aspx

"Mojtaba Faridzad" <mf*******@hotmail.com> wrote in message
news:un**************@TK2MSFTNGP15.phx.gbl...
Hi,

with SetDataBinding( ) a DataGrid shows a DataView. user can select some
rows in the grid by holding cotrol key. when user clicks on Delete button, I should delete all selected rows. I am trying to delete these lines from the dataview like this:

for (int i=0; i < dataView.Count; i++)
if (dataGrid.IsSelected(i))
dataView.Delete(i);

but after deleting the first line, all other selected rows, become
unselected and I cannot delete the rest of selected rows. how can I ask
DataGrid not to reset the status of rows?

thanks


Nov 16 '05 #3
Thanks Joey and Dmitriy. I have to delete the selected records in DataSet
too. so it's easier for me to delete the records in DataSet, then reset the
DataView and show the new set in DataGrid. but I am looking to find an event
to control Delete button. then I can let DataGrid to delete the records by
selecting them in the grid and press on <Delete> key. before deleting I have
to delete the records in DataSet too. but I could not find the suitable
event. I tried to use KeyDown event in DataGrid or Form but it seems like
another event happens. Do you know how I can detect Delete key in DataGrid?
"Joey Calisay" <jo*********@yahoo.com> wrote in message
news:e4*************@tk2msftngp13.phx.gbl...
how about desselecting it first before deleting, :p. If that doesn't
work,
i'll go for a temporary storage...

"Mojtaba Faridzad" <mf*******@hotmail.com> wrote in message
news:un**************@TK2MSFTNGP15.phx.gbl...
Hi,

with SetDataBinding( ) a DataGrid shows a DataView. user can select some
rows in the grid by holding cotrol key. when user clicks on Delete
button,

I
should delete all selected rows. I am trying to delete these lines from

the
dataview like this:

for (int i=0; i < dataView.Count; i++)
if (dataGrid.IsSelected(i))
dataView.Delete(i);

but after deleting the first line, all other selected rows, become
unselected and I cannot delete the rest of selected rows. how can I ask
DataGrid not to reset the status of rows?

thanks


Nov 16 '05 #4
Hi,

You should inherit from the DataGrid class and override the ProcessCmdKey
and PreProcessMessage methods. You will have to deal with API-level messages
there, so make sure you understand the WM_KEYDOWN and WM_SYSKEYDOWN Windows
messages.

There are a couple of others: ProcessDialogKey and ProcessKeyPreview, but as
far as I remember they are not triggered by pressing the Del key.

--
Sincerely,
Dmitriy Lapshin [C# / .NET MVP]
Bring the power of unit testing to the VS .NET IDE today!
http://www.x-unity.net/teststudio.aspx

"Mojtaba Faridzad" <mf*******@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
Thanks Joey and Dmitriy. I have to delete the selected records in DataSet
too. so it's easier for me to delete the records in DataSet, then reset the DataView and show the new set in DataGrid. but I am looking to find an event to control Delete button. then I can let DataGrid to delete the records by
selecting them in the grid and press on <Delete> key. before deleting I have to delete the records in DataSet too. but I could not find the suitable
event. I tried to use KeyDown event in DataGrid or Form but it seems like
another event happens. Do you know how I can detect Delete key in DataGrid?

"Joey Calisay" <jo*********@yahoo.com> wrote in message
news:e4*************@tk2msftngp13.phx.gbl...
how about desselecting it first before deleting, :p. If that doesn't
work,
i'll go for a temporary storage...

"Mojtaba Faridzad" <mf*******@hotmail.com> wrote in message
news:un**************@TK2MSFTNGP15.phx.gbl...
Hi,

with SetDataBinding( ) a DataGrid shows a DataView. user can select some rows in the grid by holding cotrol key. when user clicks on Delete
button,

I
should delete all selected rows. I am trying to delete these lines from

the
dataview like this:

for (int i=0; i < dataView.Count; i++)
if (dataGrid.IsSelected(i))
dataView.Delete(i);

but after deleting the first line, all other selected rows, become
unselected and I cannot delete the rest of selected rows. how can I ask
DataGrid not to reset the status of rows?

thanks




Nov 16 '05 #5
Dmitriy,

thanks for your help but I don't know I can do it or not :) this is my
second week that I have started to code C# :) more over, if I use API
functions, then my code won't be in safe mode anymore, right? but I like
your solution and I keep it. I will work on that to learn more. Thanks again
Dmitriy

is there any way to know which class handled an event? it helps me to know
which method I should override.
"Dmitriy Lapshin [C# / .NET MVP]" <x-****@no-spam-please.hotpop.com> wrote
in message news:uq**************@TK2MSFTNGP15.phx.gbl...
Hi,

You should inherit from the DataGrid class and override the ProcessCmdKey
and PreProcessMessage methods. You will have to deal with API-level
messages
there, so make sure you understand the WM_KEYDOWN and WM_SYSKEYDOWN
Windows
messages.

There are a couple of others: ProcessDialogKey and ProcessKeyPreview, but
as
far as I remember they are not triggered by pressing the Del key.

--
Sincerely,
Dmitriy Lapshin [C# / .NET MVP]
Bring the power of unit testing to the VS .NET IDE today!
http://www.x-unity.net/teststudio.aspx

"Mojtaba Faridzad" <mf*******@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
Thanks Joey and Dmitriy. I have to delete the selected records in
DataSet
too. so it's easier for me to delete the records in DataSet, then reset

the
DataView and show the new set in DataGrid. but I am looking to find an

event
to control Delete button. then I can let DataGrid to delete the records
by
selecting them in the grid and press on <Delete> key. before deleting I

have
to delete the records in DataSet too. but I could not find the suitable
event. I tried to use KeyDown event in DataGrid or Form but it seems like
another event happens. Do you know how I can detect Delete key in

DataGrid?


"Joey Calisay" <jo*********@yahoo.com> wrote in message
news:e4*************@tk2msftngp13.phx.gbl...
> how about desselecting it first before deleting, :p. If that doesn't
> work,
> i'll go for a temporary storage...
>
> "Mojtaba Faridzad" <mf*******@hotmail.com> wrote in message
> news:un**************@TK2MSFTNGP15.phx.gbl...
>> Hi,
>>
>> with SetDataBinding( ) a DataGrid shows a DataView. user can select some >> rows in the grid by holding cotrol key. when user clicks on Delete
>> button,
> I
>> should delete all selected rows. I am trying to delete these lines
>> from
> the
>> dataview like this:
>>
>> for (int i=0; i < dataView.Count; i++)
>> if (dataGrid.IsSelected(i))
>> dataView.Delete(i);
>>
>> but after deleting the first line, all other selected rows, become
>> unselected and I cannot delete the rest of selected rows. how can I
>> ask
>> DataGrid not to reset the status of rows?
>>
>> thanks
>>
>>
>
>


Nov 16 '05 #6

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

Similar topics

4
by: Steve | last post by:
Visual Studio 2003 .Net / C# I have a datagrid, which is bound to a dataset at runtime when my page loads. When the user double clicks a row, I need to find out which row they have selected so...
1
by: Junkguy | last post by:
I'm having difficulty deleting rows from a datagrid. I want to put a "delete" button on a form and achieve the same functionality as hitting the "delete" key on the keyboard for the selected row of...
3
by: BBFrost | last post by:
Ok, I know how to count the number of selected datagrid rows using the code below. What has me stumped is how to determine when the selected rows within a datagrid have been changed. The...
6
by: BBFrost | last post by:
I'm using Net 1.1 (2003) SP1 & Windows 2000 Here's the issue ... Rows 12 thru 24 are selected in a datagrid. The user now unselects rows 12 thru 24 and selects rows 45 thru 70 ??? How can...
5
by: BBFrost | last post by:
Win2000 ..Net 1.1 SP1 c# using Visual Studio Ok, I'm currently in a "knock down - drag out" tussle with the .Net 1.1 datagrid. I've come to realize that a 'block' of rows highlighted within...
1
by: Alex K. | last post by:
I need to be able to jump to first selected row in DataGrid. How can I do this without using IsSelected for each row? Is there some sort of collection which contains all selected rows? Thank you.
2
by: Ryan Liu | last post by:
private void dt_RowDeleted(object sender, DataRowChangeEventArgs e) { int id= (int)e.Row; if(id >5) { e.Row.RejectChanges(); MessageBox.Show(this, "Can not delete!" + id); }
3
by: Karl Rhodes | last post by:
I have a datagridview which is populated via a datatable. What I would like to dynamically set a selected row and have that row show up in the datagridview and not have to manually scroll to find...
9
by: Hamed | last post by:
Hello I have a DataGrid that a is bound to a DataTable. Some of the rows in the DataTable should not be deleted. How can I prohibit deleting of some identified rows? The problem could be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.