472,096 Members | 2,215 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,096 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 14575
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Steve | last post: by
1 post views Thread by Junkguy | last post: by
1 post views Thread by Alex K. | last post: by
9 posts views Thread by Hamed | last post: by

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.