473,320 Members | 2,164 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,320 software developers and data experts.

Datagrid multiselect

is it possible to turn off the multiselect in a Datagrid? if yes, how?

Erald Kulk
Nov 15 '05 #1
6 12923
Hello Erald,

--
Dmitriy Lapshin
X-Unity Unit Testing and Integration Environment
http://x-unity.miik.com.ua
Deliver reliable .NET software
"Erald Kulk" <er***@delta-travel.nl> wrote in message
news:d9**************************@posting.google.c om...
is it possible to turn off the multiselect in a Datagrid? if yes, how?

Erald Kulk


Nov 15 '05 #2
Hello Erald,

This can most likely be done, but requires non-trivial efforts. You will
need to inherit from a DataGrid and override its OnMouseDown,
ProcessDialogKey and ProcessKeyPreview methods in order to tap into keyboard
and mouse navigation and disable multi-select operations.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Unit Testing and Integration Environment
http://x-unity.miik.com.ua
Deliver reliable .NET software

"Erald Kulk" <er***@delta-travel.nl> wrote in message
news:d9**************************@posting.google.c om...
is it possible to turn off the multiselect in a Datagrid? if yes, how?

Erald Kulk


Nov 15 '05 #3

thank's for your answer, but while waiting answers I found another
simpler solution:

private void dataGridClients_MouseUp(object sender, MouseEventArgs e)
{
System.Windows.Forms.DataGrid.HitTestInfo myHitTest =
this.dataGridClients.HitTest(e.X,e.Y);
if (myHitTest.Type == DataGrid.HitTestType.Cell)
{
this.dataGridClients.Select(myHitTest.Row);
}
}

Now only one row is selected, but not when you click on
the rowheader, therefore you have to implement the mouseclick likewise
also and mousemove where you locally store the mouse x and y position

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 15 '05 #4
Erald,

Now click on a row to select it, hold the Shift key and press the Down key.
Two rows will be selected as a result. More than that, I may be overlooking
something, but as far as I remember, the Select method does not de-select
other already selected rows. DataGrid has a protected ResetSelection (or
named something like that) method to reset current selection.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Unit Testing and Integration Environment
http://x-unity.miik.com.ua
Deliver reliable .NET software

"Erald Kulk" <er***@delta-travel.nl> wrote in message
news:uo**************@TK2MSFTNGP10.phx.gbl...

thank's for your answer, but while waiting answers I found another
simpler solution:

private void dataGridClients_MouseUp(object sender, MouseEventArgs e)
{
System.Windows.Forms.DataGrid.HitTestInfo myHitTest =
this.dataGridClients.HitTest(e.X,e.Y);
if (myHitTest.Type == DataGrid.HitTestType.Cell)
{
this.dataGridClients.Select(myHitTest.Row);
}
}

Now only one row is selected, but not when you click on
the rowheader, therefore you have to implement the mouseclick likewise
also and mousemove where you locally store the mouse x and y position

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!


Nov 15 '05 #5


Dmitriy,

thanks for your concern, I immediately tested it, but when pressing the
shift or control button I can still only select one row....maybe because
of my additional methods at the mouseclick and mousemove events... let
me show them:

private void dataGridClients_MouseMove(object sender, MouseEventArgs e)
{
this.mouseX = e.X; // global variables
this.mouseY = e.Y;
}

private void dataGridClients_Click(object sender,
EventArgs e)
{
System.Windows.Forms.DataGrid.HitTestInfo myHitTest =
this.dataGridClients.HitTest(mouseX,mouseY);
if (myHitTest.Type == DataGrid.HitTestType.RowHeader)
{
for(int i = 0 ; i < this.dataGridClients.VisibleRowCount; i++)
{
this.dataGridClients.UnSelect(i);
}
this.dataGridClients.Select(myHitTest.Row);
}
}

this one I also implemented. But it's for when people navigate through
the datagrid with the arrow keys:

private void dataGridClients_CurrentCellChanged(object sender, EventArgs
e)
{
for(int i = 0 ; i < this.dataGridClients.VisibleRowCount; i++)
{
this.dataGridClients.UnSelect(i);
}
this.dataGridClients.Select(this.dataGridClients.C urrentRowIndex);
}

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 15 '05 #6


Dmitriy,

so you where right. after testing more I was able to select 2 rows when
holding down the shift button and pressing the mouse button on a
selected row then while holding down everything moving the mouse to an
unselected row. But I resolved this problem by adding these lines to the
mouseup button:

for(int i = 0 ; i < this.dataGridClients.VisibleRowCount; i++) {
this.dataGridClients.UnSelect(i);
}

now it unselects everything before selecting one row.

Erald

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 15 '05 #7

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

Similar topics

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....
2
by: Chris Plowman | last post by:
Hi all, I was wondering if anyone can help me with a really annoying problem I have been having. I made a derived datagrid class that will select the row when a user clicks anywhere on a cell...
1
by: Ghost | last post by:
Can anybody tell me how do I use DataGrid multiselect rows? What for is it?
1
by: G. Dean Blake | last post by:
Is there any way to make the datagrid a multiselect grid? Thanks, G
1
by: Wolffang | last post by:
From: "Wolffang" <javid@techlite.co.uk> Subject: How to do a multiple select and update in a datagrid Date: 23 October 2004 21:28 Using Visual studio.net VB I have a datagrid that brings...
1
by: Raed Sawalha | last post by:
i have aspx page with user control containing a datagrid , the datagrid has TempleteColumn with checkbox in header and item ( doing multiselect task) I wondering how Can get the checkboxes status...
7
by: BobAchgill | last post by:
I am trying to decide which of these controls to use to implement letting my user select a full row from MyList. The MyList has several columns which would be nice to sort by at run time. The...
2
by: Bill nguyen | last post by:
I've been using Datagrid for most of my app's data entry screens. Now I have the need for users to select multiple rows for printing. Is it possible with Datagrid items? Thanks Bill
2
by: velocius | last post by:
i use the current code to reselect a line of code in my datagrid int currentRow = dgUsers.SelectedRows.Index; dgUsers.Refresh(); dgUsers.Rows.Selected = true; this reselects the line (it...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.