By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,651 Members | 1,757 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,651 IT Pros & Developers. It's quick & easy.

deleting selected rows in a DataGrid

P: n/a
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
Share this Question
Share on Google+
5 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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.