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

c# Winforms DataGrid: What's the difference between highlighted and selected rows ???

P: n/a
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 a datagrid do
not << constitute a set of 'selected' records. Apparently one and only

one row may be 'selected' in a datagrid. By selected row I mean the row
pointer within the datagrid datasource.

I was trying to set up a process that would allow the user to select a set
of rows in DataGrid #1 and then mash a button that would transfer those rows
to DataGrid #2. The rows would then be removed from DataGrid #1.

I've tried a couple iterations of the following code.
1st try ... this code simply moved the record at the datagrid record pointer
and ignored the other highlighted records. Apparently the dv[i].Delete( );
statement somehow unhighlights the rest of the datagrid records.
//' DERIVE the source table for the Search Results Grid.
CurrencyManager cm = (CurrencyManager)this.BindingContext
[this.dgSearchResults.DataSource,this.dgSearchResul ts.DataMember];

DataView dv = (DataView)cm.List;

for(int i=0; i < dv.Count; ++i)
{
if(this.dgSearchResults.IsSelected(i))
{
mDs.Tables[this.mSelectedDirectoryIDsTableName].Rows.Add
(new Object[] {
dv[i]["directory_id"],
dv[i]["display_name"],
dv[i]["street1"],
dv[i]["city"],
dv[i]["last_updt_date"]
});
dv[i].Delete( );
}
}
2nd try ...

This example moves all of the selected datagrid #1 records to datagrid #2,
deletes the datagrid #1 record designated by the datagrid #1 record pointer
and leaves the other 'formerly highlighted' records in datagrid #1 and
unhighlighted. This is stronger proof that dv[i].Delete( ); causes the
records in datagrid #1 to be unselected.

//' DERIVE the source table for the Search Results Grid.
CurrencyManager cm = (CurrencyManager)this.BindingContext
[this.dgSearchResults.DataSource,this.dgSearchResul ts.DataMember];

DataView dv = (DataView)cm.List;

for(int i=0; i < dv.Count; ++i)
{
if(this.dgSearchResults.IsSelected(i))
{
mDs.Tables[this.mSelectedDirectoryIDsTableName].Rows.Add
(new Object[] {
dv[i]["directory_id"],
dv[i]["display_name"],
dv[i]["street1"],
dv[i]["city"],
dv[i]["last_updt_date"]
});
}
}

for(int i=0; i < dv.Count; ++i)
{
if(this.dgSearchResults.IsSelected(i))
{
dv[i].Delete( );
}
}

The only solution I can see here is to pass all the highlighted datagrid #1
records and 'tag' them in some way; then write a method to hunt the tagged
records down, move them to datagrid #2 and then delete them from datagrid
#1.

After working with c# for more than 2 years I still find myself stunned at
how much of a PIA seemingly simple processes like this can be. I'm REALLY
hoping some of you wizards out there have a better / more elegant solution
than this. I've got to admit that even after all this time the Currency
Manager mechanism is still a mystery to me ... if it wasn't for help from
this group I'd have been sunk long ago.

Thanks in advance.

Barry
in Oregon

ba***********@wrd.state.REMOVE.THE.C....REPLY.o r.us


Nov 16 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Hi Barry,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that you need to transfer the selected rows
from DataGrid #1 to DataGrid #2 when a button is clicked. If there is any
misunderstanding, please feel free to let me know.

As you know, dv[i].Delele() will deselect all the other rows. So we cannot
use that directly. I think we can fist go through all the rows in the grid
and use DataGrid.IsSelected(int) method to decide which rows have been
selected. We put the indexes to an array. Then move the rows according to
the array.

HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Nov 16 '05 #2

P: n/a
Kevin,

Thanks for your prompt reply, its very much appreciated. I was hoping that
the datagrid had a better method for tracking when a user highlights a
different set of rows within a datagrid. Oh, well.

With your help here and your answer to my "c# Winforms DataGrid: What's the
difference between highlighted and selected rows ???" question I think I can
set up a mechanism that will allow me to accomplish what I'm trying to do.

Thanks again.

Barry
in Oregon
"Kevin Yu [MSFT]" <v-****@online.microsoft.com> wrote in message
news:gg**************@cpmsftngxa10.phx.gbl...
Hi Barry,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that you need to transfer the selected rows
from DataGrid #1 to DataGrid #2 when a button is clicked. If there is any
misunderstanding, please feel free to let me know.

As you know, dv[i].Delele() will deselect all the other rows. So we cannot
use that directly. I think we can fist go through all the rows in the grid
and use DataGrid.IsSelected(int) method to decide which rows have been
selected. We put the indexes to an array. Then move the rows according to
the array.

HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Nov 16 '05 #3

P: n/a
Hi Barry,

I think the names of methods lead to misunderstanding. Actually Selected
means the row that mouse is pushed down. The all the rows with blue
backgroud color are highlighted. IsSelected method actually mean
IsHighlighted.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Nov 16 '05 #4

P: n/a
Thanks Kevin,

That's the understanding that I finally reached. I finally ended up passing
the data grid 2 times. The 1st time I tagged the 'highlighted' rows
and the 2nd pass I operated on the 'tagged' rows.

Best wishes.

Barry
in Oregon

"Kevin Yu [MSFT]" <v-****@online.microsoft.com> wrote in message
news:By**************@cpmsftngxa10.phx.gbl...
Hi Barry,

I think the names of methods lead to misunderstanding. Actually Selected
means the row that mouse is pushed down. The all the rows with blue
backgroud color are highlighted. IsSelected method actually mean
IsHighlighted.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Nov 16 '05 #5

P: n/a
Hi Barry,

Thanks for sharing your experience with all the people here. If you have
any questions, please feel free to post them in the community.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Nov 16 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.