6

I have an application (winforms, c#) that displays data in a Listview in a very usual way - the first row is headers, the first column in each row is header and the following sub-items is the data itself.

I want the first column (the headers columns) always visible and the horizontal scroll to affect the other columns only.

i don't think it is possible in winforms listview (am i wrong?). Hence, i'm thinking to split the listview to two listviews - one for headers and the second for data. In that case, i need to connect the vertical scroll bars - a task which i find to be harder than i've expected.

Am i taking a wrong path (e.g. would it be easier to use a different control)? If not, any pointers on how to implement it?

Note: Winforms Listview has poor API (e.g. no scrolling event) and is known as buggy, so i'm looking a working sample rather than MSDN links...

Thanks

Hertzel Guinness
  • 5,912
  • 3
  • 38
  • 43

3 Answers3

7

As already noted the DataGridView supports this behaviour, but nobody told how this will be done:

To enable this feature simply set the Frozen property of a column. Further informations can also be found in this How to: Freeze Columns in the Windows Forms DataGridView Control.

Oliver
  • 43,366
  • 8
  • 94
  • 151
  • yes, but only for a few minutes (got the same error message). But now it works again like a charm. (Very strange). To make it easier in the future i replaced the text by the full name of the article. So if the link is dead again, you can better search for it. – Oliver Apr 28 '11 at 09:33
  • 1
    @Hertzel - your proposed edit was basically a carbon copy of a link that @Oliver had already included. And i've fixed the second link, should work fine now. – slugster Apr 28 '11 at 10:04
  • @Hertzel and @slugster: rolled back to my last version, cause the link was the same as mine, except it was link to VS8.5. Without this parameter in brackets it will always jump to the latest version of this article which i prefer. – Oliver Apr 28 '11 at 10:19
1

Did you try using DataGridView instead?

Edit:

In case you run into problems with setting row headers text, take a look at this post (basically, you set row header text upon item being added to grid).

Community
  • 1
  • 1
k.m
  • 30,794
  • 10
  • 62
  • 86
1

I think you have to try to use the DatagridView instead of the listbox. As far as I know, the DataGridView supports this.

Rhapsody
  • 6,017
  • 2
  • 31
  • 49