Home All Groups Group Topic Archive Search About

how to locate the selected item in the datagrid

Author
24 Nov 2004 1:37 AM
zbcong
hello
when a line in the datagrid is selected,how can i know in the program whick
line is selected(just like that the listview can return the
"selecteditems",but datagrid can't)?

thank you!!

Author
24 Nov 2004 7:31 AM
Stephan Mader
hi,

to check if a specific row is selected  use the datagrid's "IsSelected"
method. If you want to get all selected rows, you have to loop through all
rows and remember each selected row's index.

Regards,
Stephan

Show quote
"zbcong" <congzhe***@capinfo.com.cn> schrieb im Newsbeitrag
news:OVOMeYc0EHA.2788@TK2MSFTNGP15.phx.gbl...
> hello
> when a line in the datagrid is selected,how can i know in the program
whick
> line is selected(just like that the listview can return the
> "selecteditems",but datagrid can't)?
>
> thank you!!
>
>
Author
24 Nov 2004 5:38 PM
Pieter Jansen van Vuuren
Don't you just love inheritance?
this sample inherits from DataGrid and then returns an IList of
SelectedItems.

HTH

Pieter

"zbcong" <congzhe***@capinfo.com.cn> wrote in message
news:OVOMeYc0EHA.2788@TK2MSFTNGP15.phx.gbl...
> hello
> when a line in the datagrid is selected,how can i know in the program
whick
> line is selected(just like that the listview can return the
> "selecteditems",but datagrid can't)?
>
> thank you!!
>
>

[attached file: DataGridEx.cs]

AddThis Social Bookmark Button