How to scroll only the right side of a table, listview, or datagrid?
Question
Let's say I have data structures that're something like this:
Public Class AttendenceRecord
Public CourseDate As Date
Public StudentsInAttendence As Integer
End Class
Public Class Course
Public Name As String
Public CourseID As String
Public Attendance As List(Of AttendenceRecord)
End Class
And I want a table that looks something like this:
| Course Name | Course ID | [Attendence(0).CourseDate] | [Attendence(1).CourseDate]| ... | Intro to CS | CS-1000 | 23 | 24 | ... | Data Struct | CS-2103 | 15 | 14 | ...
How would I, in the general case, get everything to the right of Course ID to be horizontally scrollable, while holding Course Name and Course ID in place? Ideally using a table, listview, or datagrid inside ASP.NET and/or WinForms.
Solution
You can get this functionality from the System.Windows.Forms.DataGridView control. When you create columns you can set them to be frozen which will then only scroll those columns to the right of the frozen column(s).
OTHER TIPS
In pure .Net I don't know of anything. There are CSS Solutions for a fixed header. But a fixed left column, in my experience, requires some javascript finangling.
Took me a minute to find the old example. Host has since gone down. http://web.archive.org/web/20080215013647/http://www.litotes.demon.co.uk/example_scripts/tableScroll.html
This is the mechanism I used to get it to work: Take a normal table, and separate it out into 4 other tables. Get the column widths and row heights to match up using business constraints, and then link the onscroll event to scroll the other tables.
Here's an example using just HTML and CSS to achieve what I think you're looking for:
http://www.shrutigupta.com/index.php/2005/12/12/how-to-create-table-with-first-column-frozen/