Reputation: 463
I love ObjectListView, but I am having a heck of a problem with getting columns to show up in the right-click menu.
When I add columns via the objectlistview.Columns.Add(olvcolumn) scenario, and set the olvcolumn.IsVisible = False, it just ignores it, and displays the column.
And even when the columns show up, they do NOT show up in the right-click column header menu. I can see the sorting and grouping for each column, but not the columns.
And when I try to do it at runtime, and do a objectlistview.RebuildColumns(), ALL OF THE COLUMNS DISAPPEAR.
What the heck am I doing wrong? Here is the code for initializing the objectlistview (I'm using the fastlistview subclass)
Me.lvSelectedFiles.HideSelection = False
Me.lvSelectedFiles.FullRowSelect = True
Me.lvSelectedFiles.GridLines = True
Me.lvSelectedFiles.Dock = System.Windows.Forms.DockStyle.Fill
Me.lvSelectedFiles.Location = New System.Drawing.Point(3, 3)
Me.lvSelectedFiles.Name = "lvSelectedFiles"
Me.lvSelectedFiles.Size = New System.Drawing.Size(937, 101)
Me.lvSelectedFiles.TabIndex = 8
Me.lvSelectedFiles.UseCompatibleStateImageBehavior = False
Me.lvSelectedFiles.View = System.Windows.Forms.View.Details
Me.lvSelectedFiles.ShowCommandMenuOnRightClick = True
Me.lvSelectedFiles.ShowFilterMenuOnRightClick = True
Me.lvSelectedFiles.UseAlternatingBackColors = True
Me.lvSelectedFiles.AlternateRowBackColor = SystemColors.Control
Me.lvSelectedFiles.SelectColumnsOnRightClick = True
Me.lvSelectedFiles.SelectColumnsOnRightClickBehaviour = BrightIdeasSoftware.ObjectListView.ColumnSelectBehaviour.Submenu
And here is the logic for adding a column (doesn't make sense to show all the code, since I do the same thing for each column)
olvcolhdr = New OLVColumn()
olvcolhdr.Text = "File Type"
olvcolhdr.Width = 150
olvcolhdr.DisplayIndex = 4
olvcolhdr.UseFiltering = True
olvcolhdr.Searchable = True
olvcolhdr.HeaderTextAlign = HorizontalAlignment.Left
olvcolhdr.TextAlign = HorizontalAlignment.Left
olvcolhdr.AspectGetter = Function(orow As Object)
Dim s As FoundFile = DirectCast(orow, FoundFile)
Dim sext As String = FileExtensionInfo(AssocStr.FriendlyDocName, s.Extension)
Return (sext)
End Function
lvSelectedFiles.Columns.Add(olvcolhdr)
olvcolhdr = New OLVColumn()
olvcolhdr.Text = "Size"
olvcolhdr.Width = 75
olvcolhdr.DisplayIndex = 5
olvcolhdr.UseFiltering = True
olvcolhdr.HeaderTextAlign = HorizontalAlignment.Left
olvcolhdr.TextAlign = HorizontalAlignment.Right
olvcolhdr.AspectName = "Length"
olvcolhdr.AspectToStringFormat = "{0:#,##0}"
olvcolhdr.Searchable = True
olvcolhdr.IsVisible = False
lvSelectedFiles.Columns.Add(olvcolhdr)
In the above two columns, the first is supposed to be initially visible, and the second one invisible. But they BOTH show up as visible. I am NOT trying to set the first column to invisible. That's ALWAYS visible and that's okay...
And if I do the above, and then call 'RebuildColumns()', ALL the columns disappear.
Ack. Please help!
Upvotes: 1
Views: 1549
Reputation: 463
Well, it seems I'm the only one who answers my questions. For anyone who has this issue in the future, if columns DON'T show up in the context menu, it's because you need to add the OLVColumns TWICE! Once to the column header collection, and another time (I do this BEFORE I add columns to the header collection, but it may make no difference) using the objectlistview.AllColumns function. As in:
objectlistview.AllColumns.Add(onewolvcolumn)
You will see the data show up, if you don't perform the extra assignment (at least I did by using the AddObject function when adding data), but you will not see any columns in the context menu list, and if you do a RebuildColumns() call, it will erase ALL your columns in the listview also.
So, the final code looks like this (just the relevant part):
olvcolhdr = New OLVColumn()
olvcolhdr.Text = "Size"
olvcolhdr.Width = 75
olvcolhdr.DisplayIndex = 6
olvcolhdr.UseFiltering = True
olvcolhdr.Searchable = True
olvcolhdr.HeaderTextAlign = HorizontalAlignment.Left
olvcolhdr.TextAlign = HorizontalAlignment.Right
olvcolhdr.AspectName = "Length"
olvcolhdr.AspectToStringFormat = "{0:#,##0.0}"
lvFindInsideFiles.AllColumns.Add(olvcolhdr)
lvFindInsideFiles.Columns.Add(olvcolhdr)
olvcolhdr = New OLVColumn()
olvcolhdr.Text = "Message"
olvcolhdr.Width = 150
olvcolhdr.DisplayIndex = 7
olvcolhdr.UseFiltering = True
olvcolhdr.Searchable = True
olvcolhdr.HeaderTextAlign = HorizontalAlignment.Left
olvcolhdr.TextAlign = HorizontalAlignment.Left
olvcolhdr.AspectName = "ErrorMessage"
lvFindInsideFiles.AllColumns.Add(olvcolhdr)
lvFindInsideFiles.Columns.Add(olvcolhdr)
See where I added the olvcolhdr (which is an OLVColumn object) twice, once using the Columns collection and again using the AllColumns. I couldn't find this ANYWHERE in the documentation, or in any of the examples EXCEPT the complex example, which I had not looked at, well, because I had enough issues to worry about with the BASIC examples!
Upvotes: 6