Hello all,
I can usually find solutions to my .NET problems by searching these
groups, but I'm stumped on this one. I have a datagrid in VB.NET (2.0
framework). I want to disable sorting on the first column in the grid
only. I havent found a way to reliably do this yet.
I tried putting the following code in the datagrid's mouse down event
Dim hti As DataGrid.HitTes tInfo
hti =
dgCompList.HitT est(dgCompList. PointToClient(C ontrol.MousePos ition))
If hti.Type = DataGrid.HitTes tType.ColumnHea der Then
If hti.Column = 0 Then
dgCompList.Tabl eStyles(0).Allo wSorting = False
dgCompList.Allo wSorting = False
Else
dgCompList.Tabl eStyles(0).Allo wSorting = True
dgCompList.Allo wSorting = True
End If
End If
This almost works, except the first time I click on the column heading
for row zero, the sort happens, but further clicks behave as expected
(no sorting). Its almost as though the sort event fires before I am
able to disable the sorting on the grid. Any ideas? Thanks in
advance.
Eric 1 7132
Thanks, that did the trick. Here is the code I'm using to disable
sorting on column zero only:
Public Class CustomDataGrid
Inherits DataGrid
Protected Overrides Sub OnMouseDown(ByV al e As
System.Windows. Forms.MouseEven tArgs)
Dim hti As DataGrid.HitTes tInfo = Me.HitTest(New Point(e.X, e.Y))
'This keeps column zero from being sorted
If hti.Type = DataGrid.HitTes tType.ColumnHea der Then
If hti.Column = 0 Then
Return 'no baseclass call
End If
End If
MyBase.OnMouseD own(e)
End Sub
Public Sub New()
End Sub
End Class
Ken wrote:
Hi,
I think you are going to have to suppress the mouse down message
when the user is over the column header you did not want sorted like in this
tip here for preventing row and column resize.
http://www.vb-tips.com/dbpages.aspx?...9-526ea7d7382d
Since you are using .net 2.0 you could always use a datagridview instead of
a datagrid. You could prevent an column form being sorted like this
DataGridView1.C olumns(0).SortM ode = DataGridViewCol umnSortMode.Not Sortable
Ken
-----------------
"ECD" wrote:
Hello all,
I can usually find solutions to my .NET problems by searching these
groups, but I'm stumped on this one. I have a datagrid in VB.NET (2.0
framework). I want to disable sorting on the first column in the grid
only. I havent found a way to reliably do this yet.
I tried putting the following code in the datagrid's mouse down event
Dim hti As DataGrid.HitTes tInfo
hti =
dgCompList.HitT est(dgCompList. PointToClient(C ontrol.MousePos ition))
If hti.Type = DataGrid.HitTes tType.ColumnHea der Then
If hti.Column = 0 Then
dgCompList.Tabl eStyles(0).Allo wSorting = False
dgCompList.Allo wSorting = False
Else
dgCompList.Tabl eStyles(0).Allo wSorting = True
dgCompList.Allo wSorting = True
End If
End If
This almost works, except the first time I click on the column heading
for row zero, the sort happens, but further clicks behave as expected
(no sorting). Its almost as though the sort event fires before I am
able to disable the sorting on the grid. Any ideas? Thanks in
advance.
Eric This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Brett P. |
last post by:
Hello,
I am trying to have only one column sortable within a
data grid. I know you set the allowsorting property to
true on the style or the grid, but this enables sorting
for all columns. Is there a way to override this
implementation so that only a few or one of the columns
may be sorted?
thanks,
-brett
|
by: Jon Davis |
last post by:
I have a Windows Forms app in which I have a DataGrid control. I have a
custom class that has several properties exposed, and I have made this
class, or a collection thereof, the DataSource of the DataGrid. This neat
feature of the DataGrid allows the properties to be displayed in a
Collection of this class.
Now, how do I order the columns (not to be confused with the rows, which is
managed by the collection)? Is there a simple process...
|
by: andrewcw |
last post by:
After I made a nice application with WINFORM I tried to apply much of the same code, but there are lost of differences.
I load the grid colors, column width, column header from a xml data file.
But when I use datagrid.bind - it pulls in all the data to its own columns.
Ex:
gridTX.DataSource = ds.Tables;
this.AttachXMLdrivenStyle(gridTX,mappTableName);
gridTX.DataBind(); // my columns are not mapped over....but stand alone.
|
by: Rhodri |
last post by:
Hi all
I have a datagrid which can display upto 20,000 records and the
viewstate gets very big. I have tried turning of viewtate using
EnableViewState = false both on the parent page and on the DataGrid
itself, however when i view the generated html source there is still
an enourmous viewstate.
The columns for my grid are being generated dynamically in the code
behind, is this causing the problem?
|
by: Fluxray |
last post by:
--Background:
I have a webform including a datagrid. The datagrid is using template. Its
ItemTemplate is used to display a look-up-table with labels. its
EditItemTemplate is used to edit a row in the look-up-table with textboxes. I
have a linkbutton in each row (causevalidation = false) named 'Edit' to post
the page back such that the page is switch from display mode to edit mode
(labels -> textboxes for the row to be edited), and the...
| |
by: Jay Villa |
last post by:
Is it possible to update only few columns in datagrid during OnUpdateCommand
event ? If so, could you help me ....
-thanks
Jay
|
by: nate axtell |
last post by:
In VB .NET I load the contents of an Excel or comma seperated values file
into a dataGrid (via a datatable). One of the columns has a comma in the
name of the column. So for the comma separated values files I put double
quotes are the column name. What I see is that the name ends up getting
displayed correctly in the DataGrid column, "Class (1,2,3)". When I click
on the column to sort I see the following error:
"Additional information:...
|
by: Tmuld |
last post by:
Hello,
I have a complete table within a dataset.
I want a dataview to show particular filtered data - works great with
the dv.rowfilter.
But can I display only certain columns that are filtered?
Right now in my rowfilter I have something like this:
|
by: **Developer** |
last post by:
I need to sort the columns of a ListView.
Some columns contain dates and others contain integers.
What I did once before is in the Compare method I tried date and if that
failed I did Integer.
Seems kinda not nice - is there a better way?
Thanks
|
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...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |