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

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

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
5 9154
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Gerg | last post by:
The datagrid has a tablestyle applied to it, and there are DataGridTextBoxColumn and each DataGridTextBoxColumn has an array of DataGridTextBox objects. Private Sub highlight(ByVal str As...
0
by: Tom Hughes | last post by:
I want to change one field of all selected rows to a provided value. Problem 1 I am using the Binding Manager Base to bind the datagrid to the appropriate dataTable as recommended by KB817247....
0
by: MrNobody | last post by:
hey guys... I'm trying to make my DataGrid have selection behavior similar to WindowsExplorer, where I can hold CTRL to add rows to a multi-row selection. Thanks to someone else on this...
2
by: Bob Hollness | last post by:
Hi group. I am a newbie to ASP.NET as you will see from some of the questions I may ask! I have a datagrid which I have populated from a database. It works great! I have added a column, via...
0
by: Jennifer | last post by:
I had this beautiful datagrid on an ASP page (VB.Net as the code behind). When I clicked on a Select Button, the row was selected and the background color changed the way it was supposed to. The...
13
by: pmcguire | last post by:
I have a DataGrid control for which I have also created several new extended DataGridColumnStyles. They behave pretty nicely, but I can't figure out how to implement Selected Item formatting for...
1
by: .NETn00b | last post by:
Is this possible? I need to create a multi-select DataGrid, and I cannot use CheckBoxes. I want the selected rows to appear highlighted. One possible work-around that occurred to me was to...
2
by: ewingate | last post by:
I have a form with two text boxes, a button, and a datagrid control which is bound to my SQL DB. There are two columns on the datagrid, one for each of the textboxes on the form. I have already...
0
by: frostbb | last post by:
Ok, We've got a bunch of apps that we've migrated from Net 1.0 to Net 2.0. The apps were basically upgraded using the VS2005 migrate. The user control that was using a DataGrid.IsSelected(i)...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.