470,641 Members | 1,695 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,641 developers. It's quick & easy.

How do you clear selected rows in DataGrid?

There does not seem to be any way except a method called UnSelect which
requires an index- which I don't have.... is there any other way to simply
deselect rows or perhaps iterate through selected rows to get their index and
call unselect on them?
Nov 16 '05 #1
3 13161
CurrencyManager cm =
(CurrencyManager)this.BindingContext[this.dgCharges.DataSource,
this.dgCharges.DataMember];
System.Data.DataView dv = (System.Data.DataView)cm.List;

for(int i=0; i<dv.Count; i++)
if(this.dgCharges.IsSelected(i))
this.dgCharges.UnSelect(i);
Nov 16 '05 #2


"John J. Hughes II" wrote:
CurrencyManager cm =
(CurrencyManager)this.BindingContext[this.dgCharges.DataSource,
this.dgCharges.DataMember];
System.Data.DataView dv = (System.Data.DataView)cm.List;

for(int i=0; i<dv.Count; i++)
if(this.dgCharges.IsSelected(i))
this.dgCharges.UnSelect(i);


Ouch- brute force !

I found another person who had the same problem and they used the
CurrentCellChanged event to put any cell indexes selected into an ArrayList
which can then be iterated through to perform some action on the selected
rows or to just UnSelect them all- looks like it works quite well.

Thanks for your reply!
Nov 16 '05 #3
"MrNobody" <Mr******@discussions.microsoft.com> wrote in message
news:6B**********************************@microsof t.com...


"John J. Hughes II" wrote:
CurrencyManager cm =
(CurrencyManager)this.BindingContext[this.dgCharges.DataSource,
this.dgCharges.DataMember];
System.Data.DataView dv = (System.Data.DataView)cm.List;

for(int i=0; i<dv.Count; i++)
if(this.dgCharges.IsSelected(i))
this.dgCharges.UnSelect(i);


Ouch- brute force !

I found another person who had the same problem and they used the
CurrentCellChanged event to put any cell indexes selected into an
ArrayList
which can then be iterated through to perform some action on the selected
rows or to just UnSelect them all- looks like it works quite well.

Thanks for your reply!


Yea I like really big hammers :)

I assume you mean cell index by the index into the dataset of the record?
If not I have had problems with the cell number changing.

One problem I would have with putting the data into an array is that you
then need to do a search for each record. Whereas if you are searching on
an index it's quick it will still have to read X records before finding the
record you are looking for. So if you have 100 records tagged out of 500
you will be doing 100 searches times X records. I would have a tendency to
think that if X averaged 5 records per search you are still looking at 500
records. If 499 records are tagged then you are looking at 2495 records.
But on the other side if there is only 1 record tagged you are only looking
at 5 records.

Mostly it would be a semantics thing I think where one or the other would be
faster depending on the number of records in the dataset.

Regards,
John
Nov 16 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Steve | last post: by
4 posts views Thread by R Agam | last post: by
5 posts views Thread by Mojtaba Faridzad | last post: by
1 post views Thread by Alex K. | last post: by
4 posts views Thread by Mike L | last post: by
reply views Thread by Flack | last post: by
???
1 post views Thread by Stoney L | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.