Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DataGrid Scrolling and Sorting

Status
Not open for further replies.

EBECK

Programmer
Nov 11, 2004
14
US
I work for a homeless shelter and have created a Visual Basic application using Visual Studio .NET 2003. I have two questions about the DataGrid object I'm using in my application.

1. When the DataGrid is initially presented to the user (on form load) the grid is empty. The form load (frmMain_Load) has the following code:
grdDailyAttendance.CaptionText = "Daily Attendance Records"
grdDailyAttendance.DataSource = DataSet11
grdDailyAttendance.DataMember = "tblDailyAttendance"
grdDailyAttendance.AllowDrop = False
grdDailyAttendance.AllowNavigation = False
grdDailyAttendance.AllowSorting = False

The user clicks a button to select the Daily Attendance records for a particular day. The number of records loaded into the DataGrid for the selected day is larger than the display area of the DataGrid. The user is unable to scroll down the DataGrid to view the records below the display area (The vertical scroll bar has nothing to click and drag to scroll down). How can I add vertical scrolling to the DataGrid?

2. How do I keep the DataGrid from sorting the data when the user clicks the column headers? I thought the AllowSorting method would not allow the DataGrid to sort the data, however the grid sorts the data when the column header is clicked.

Does anyone have any ideas for these two issues? Thank you in advance for your time and consideration.

Ed
 
Set these values at design time and see what happens.
 
I tried your suggestion, but the results are the same. Thanks again for your feedback.

Ed
 
To prevent column sorting you have to do the following.
Create your own derived subclassed grid from the Datagrid
Code:
Public Class MyDataGrid 
 
Inherits DataGrid 
 
Protected Overrides Sub OnMouseDown(ByVal e As System.Windows.Forms.MouseEventArgs) 
 
Dim pt As New Point(e.X, e.Y) 
Dim hti As DataGrid.HitTestInfo = Me.HitTest(pt) 

If hti.Type = HitTestType.ColumnHeader 
    'don't sort columns
     Return 'don't call baseclass 
End If 
 
MyBase.OnMouseDown(e) 
 
End Sub 'OnMouseDown 
 
End Class 'MyDataGrid



Sweep
...if it works dont f*** with it
curse.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top