473,804 Members | 3,700 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Datagrid multiselect

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

Erald Kulk
Nov 15 '05 #1
6 12950
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.goo gle.com...
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,
ProcessDialogKe y and ProcessKeyPrevi ew 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.goo gle.com...
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.dataGridCl ients.HitTest(e .X,e.Y);
if (myHitTest.Type == DataGrid.HitTes tType.Cell)
{
this.dataGridCl ients.Select(my HitTest.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******** ******@TK2MSFTN GP10.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.dataGridCl ients.HitTest(e .X,e.Y);
if (myHitTest.Type == DataGrid.HitTes tType.Cell)
{
this.dataGridCl ients.Select(my HitTest.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(obje ct 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.dataGridCl ients.HitTest(m ouseX,mouseY);
if (myHitTest.Type == DataGrid.HitTes tType.RowHeader )
{
for(int i = 0 ; i < this.dataGridCl ients.VisibleRo wCount; i++)
{
this.dataGridCl ients.UnSelect( i);
}
this.dataGridCl ients.Select(my HitTest.Row);
}
}

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

private void dataGridClients _CurrentCellCha nged(object sender, EventArgs
e)
{
for(int i = 0 ; i < this.dataGridCl ients.VisibleRo wCount; i++)
{
this.dataGridCl ients.UnSelect( i);
}
this.dataGridCl ients.Select(th is.dataGridClie nts.CurrentRowI ndex);
}

*** 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.dataGridCl ients.VisibleRo wCount; i++) {
this.dataGridCl ients.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
1849
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. It works in all cases but one. If the field being changed is also one the user has selected as a sort column, then all but the first selections are missed. If I remove the sort from that column before or after
2
9930
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 (multi-select without modifier keys). I got that working fine, but I also wanted to keep rows selected after a sort, which I do by storing the row's id in an arraylist. The idea was to do the sort and then go back and re-select the rows with that...
1
2355
by: Ghost | last post by:
Can anybody tell me how do I use DataGrid multiselect rows? What for is it?
1
293
by: G. Dean Blake | last post by:
Is there any way to make the datagrid a multiselect grid? Thanks, G
1
1974
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 records from a stored procedure. Be selecting multiple datarows using a checkbox. All i want to do is update a field called 'Active' datatype bit from 0 to 1
1
5847
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 from aspx page this is my datagrid in the user control <asp:datagrid id="dgFoldersInfo" runat="server" BorderColor="Black" BorderWidth="0px" HeaderStyle-CssClass="tableHeaderCell" ShowFooter="True" CellPadding="3" GridLines="Horizontal"...
7
15009
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 MyList data is resident in a dataset table. I'm stuck and can't choose either because. If I choose ListView as my control I don't understand how to programmatically get the data from the dataset table
2
2019
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
1904
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 turns blue) but the arrow pointing to a row gets reset to row one. also, my datagrid has a scroll bar for up and down, and when i select the last row, then toggle its status, the datagrid is looking at the top rows, even whil the blue selected line is at...
0
9706
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10580
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10335
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10082
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6854
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5652
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4301
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3821
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2993
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.