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

Is there some way other than IsSelected in a DataGrid?

Tom
Hi,

I have been through all kinds of documentation on the datagrid and
dataviews. I have many expensive books that I have looked through. But
nothing has really helped. I want to find out and retrieve copies of
any selected records that are in a dataview. One thing I have done is
used the MouseDown event and HitTestInfo to find out what record has
been clicked on. This tells me the current record and I can retrieve
the record and add it to my collection . But what if a user holds the
Shift key down to select multiple records? What if they only use the
keyboard and bypass the mouse altogether?

I need to know what records are <B>selected</B> by the user and then
retrieve copies of them. I know of the DataGrid.IsSelected(index)
function, but what if the datagrid has a million records? I know that
sounds like an impractical amount, but I don't know how many records
will be returned by a query. I have to take a million record
possibility into account. And some of our tables have more than a
million records.

IsSelected() is not very practical when there are a lot of records. Is
there some other way?

One other thing. What if I want to get the selected DataRowView from
the dataview and then add it to a data table? I get errors saying that
you can't convert the DataRowView to a DataRow. This is even when the
schema for the DataRowView is exactly the same as the DataRow and
DataTable.

Thanks for any help on this,

Tom Graves
Nov 15 '05 #1
2 3102
Hello Tom,

I feel your pain but alas, there is NO easy way. You should tap into all the
mouse and keyboard handling to maintain a collection of selected rows
manually. This is tedious, but not impossible. First, inherit from the
DataGrid class and override its OnMouseDown and OnMouseUp methods to handle
the mouse. You can detect Shift in these methods by checking the static
Control.ModifierKeys property. Then, override the
ProcessDialogKey, ProcessCmdKey and ProcessKeyPreview methods (there may be
more methods to override, please check the MSDN on the DataGrid's protected
methods). You should arrange some experiments to find out which override is
best. For me, these were ProcessDialogKey (called when a cell is not being
edited) and ProcessKeyPreview (called when a cell IS being edited).

As an alternative solution, you can search for controls based on the
DataGrid (there definitely is a free one created by a Russian guy, it is
called SuperGrid as far as I remember), or rather switch to a commerial grid
such as ComponentOne or SyncFusion's.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

"Tom" <To********@i2.com> wrote in message
news:a6*************************@posting.google.co m...
Hi,

I have been through all kinds of documentation on the datagrid and
dataviews. I have many expensive books that I have looked through. But
nothing has really helped. I want to find out and retrieve copies of
any selected records that are in a dataview. One thing I have done is
used the MouseDown event and HitTestInfo to find out what record has
been clicked on. This tells me the current record and I can retrieve
the record and add it to my collection . But what if a user holds the
Shift key down to select multiple records? What if they only use the
keyboard and bypass the mouse altogether?

I need to know what records are <B>selected</B> by the user and then
retrieve copies of them. I know of the DataGrid.IsSelected(index)
function, but what if the datagrid has a million records? I know that
sounds like an impractical amount, but I don't know how many records
will be returned by a query. I have to take a million record
possibility into account. And some of our tables have more than a
million records.

IsSelected() is not very practical when there are a lot of records. Is
there some other way?

One other thing. What if I want to get the selected DataRowView from
the dataview and then add it to a data table? I get errors saying that
you can't convert the DataRowView to a DataRow. This is even when the
schema for the DataRowView is exactly the same as the DataRow and
DataTable.

Thanks for any help on this,

Tom Graves


Nov 15 '05 #2
Tom
Thanks Dmitriy,

I already have some of the code in the mouse down event that detects
if a modifier key was pressed but I was unaware of the other events. I
will have to put code in those other events to capture the record. I
think I will also look at those third party controls as this seems
like a lot of trouble for the most basic functionality from a
datagrid.

Thanks for the suggestions,
Tom
Nov 15 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

18
by: Stanley J Mroczek | last post by:
I Set the EditCommandColumn to Visible=False to stop people who are not allowed to make any changes to a record. How can set it to Visible=true for some users? Please answer in VB Thanks Stan
0
by: Vaughn | last post by:
How can I use Datagrid.IsSelected to find what row had been double-clicked? What would the loop include? Thanks.
1
by: TusharP | last post by:
Hi Friends, My requirement are as follow..... 1) First DataGrid display all row of one table, with this one additional column having +/- control like tree. 2) When user click on +/- control ...
1
by: Guadala Harry | last post by:
I understand that paging is a built-in feature of the DataGrid, and that paging is not built-in to other listing controls such as the DataList and the Repeater. I need to implement paging...
5
by: Flack | last post by:
Hey guys, Here is what I am trying to achieve: I have a grid, and every once in a while the grid will receive a message to add a new row and highlight it (change the backcolor) for five...
2
by: Ram | last post by:
I have a strange problem with ASP.NET 1.1 SP1 application. Application has a asp.net page which has a datagrid in it.( data grid/PAGE has large amount of data. always more than 1MB). There is a...
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)...
2
by: frostbb | last post by:
The following code works great in C# Net 1.0 & Net 1.1 apps ... doesn't work for Net 2.0 apps. Cannot get pDg.IsSelected(i) to toggle to 'true' for 'highlighted' rows in a DataGrid control. ...
0
by: frostbb | last post by:
1st I know about the new DataGridView control. For various reasons we need the IsSelected( ) method of the old DataGrid to work in the upgraded apps. I have a small test app that illustrates the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
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
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
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...

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.