Datagrid Multiple Select

A

Andy Baker

I have a VB.NET 2003 application that uses several datagrids. The behaviour
I want from the datagrid is to select (highlight) the entire row when I
click on any cell in a row. I have done this using code from syncfuson.com
to create a class that inherits from DataGridTextBoxColumn and overrides the
its Edit method. i.e.

Public Class DataGridNoActiveCellColumn
Inherits DataGridTexBoxColumn

Private SelectedRow as Integer

Protected Overloads Overrides Sub Edit (ByVal source As CurrencyManager,
ByVal rowNum as Integer...)
SelectedRow = rowNum
If (SelectedRow > -1) and (SelectedRow < source.List.Count) then
Me.DataGridTableStyle.DataGrid.Unselect(SelectedRow)
Me.DataGridTableStyle.DataGrid.Select(SelectedRow)
End if
End Sub
End Class

This works well. For certain grids, I want the user to be able to select
more than one row, and each selected row to be highlighted. To attempt to do
this I created another class similar to the above, but without the
Me.DataGridTableStyle.DataGrid.Unselect(SelectedRow) line, and created my
DataGridTableStyle using that, but it didn't work. How can I highlight
multiple rows at the same time in a .NET datagrid? Thanks in advance.

Andy Baker
 
A

Andy Baker

Hello Clay

Thanks for that. I think I understand the theory, but unfortunately I
cannot download the sample project from that address - I get a 404 error,
file not found. I have created a class DataGridMultipleSelectColumn that
inherits from DataGridTextBoxColumn, that consists of a single sub:
Protected Overloads Overrides Sub Edit(ByVal source as
CurrencyManager...)
End Sub
with an empty method. This prevents the clicked cell from being selected, as
I would expect. I have then created a class inheriting from
Windows.Forms.Datagrid and added a boolean property AllowMultipleSelection.
I then override the OnMouseDown Event as follows:
Protected Overloads Overrides Sub OnMouseDown(ByVal e as MouseEventArgs)
Dim aHitTestInfo as DataGrid.HitTestInfo
aHitTestInfo = Me.HitTest(New Point (e.X, e.Y))
If (aHitTestInfo.Type = Me.HitTestType.Cell and
AllowMultipleSelection) then
MyBase.OnRowHeaderClick(e)
End if
End Sub
However, this doesn't select the row. Is it because OnMouseDown takes an
argument of type MouseEventArgs and OnRowHeaderClick takes an argument of
EventArgs, and if so how do I convert between them? Thanks for your help.

Andy Baker
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top