473,385 Members | 1,347 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,385 software developers and data experts.

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 13325
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 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...
4
by: R Agam | last post by:
How do I get the selected Rows index in the DataGrid? Thanks, Ronen
5
by: Mojtaba Faridzad | last post by:
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...
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.
4
by: Mike L | last post by:
This is for a Win form. How do I clear all the rows in a datagrid? How do I add a record to a datagrid?
0
by: Flack | last post by:
I have pasted at the end of this message a small sample program I whipped up to do some testing. It's a form with a datagrid and two buttons. Each button clears the dataTable that is the source...
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.