472,789 Members | 1,286 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,789 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 9105
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: Rina0 | last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.