Listview question

Started by Gary Stout, November 13, 2009, 01:33:23 AM

Previous topic - Next topic

Gary Stout

How does one set the listview header labels and the number of columns? I looked through the property list for something like custom, similar to the way the tabs in a tab control are set, but didn't see anything like that.

Setting these with a custom property might be easier and more consistent with the way it is done with the tab control.

Thanks,
Gary

Rolf Brandt

I usually use a little function I had written for myself to set up the headers of a listview. I just need to send a string with column names and column width to the function.


'Usage: LViewCreateHeader hWndLView, "Col1|70,Col2|150,Col3|250"
'or: LViewCreateHeader hWndLView, "Col1,Col2,Col3", 100

Function LViewCreateHeader( _
hWndLView As Dword, _          'handle of the control
Header As String, _            'string of column headers
Opt defColWidth As Long _      'default column width
)As Long 
'This function accepts a Header string with column names and column widths
'Example: Header = "Item|200,Value|350,AnyName|200"
'Delimiter between column name and column width is chr(124)=|
'if column with is ommitted a default column width is applied
'The header string can be mixed with or without column width
    'ListView Style must be Report
Local colCount As Integer
Local i As Integer     
Local cn As String
Local colName As String
Local colWidth As Long

If defColWidth = 0 Then DefColWidth = 150

colCount = ParseCount(header, ",")
For i = colCount To 1 Step -1  'parsing goes right to left
cn = Parse$(Header,i) 

If InStr(cn,"|") > 1 Then
colName = Parse$(cn,"|",1)
colWidth = Val(Parse$(cn,"|",2))
Else
colName = cn
colWidth = defColWidth
End If
FF_ListView_InsertColumn hWndLView, 0, colName, 0, ColWidth
Next

End Function


But I agree a feature to set this up in the properties like in MyLittleGrid would be nice.

Rolf
Rolf Brandt
http://www.rbsoft.eu
http://www.taxifreeware.com
I cook with wine, sometimes I even add it to the food.
(W. C. Fields)

Paul Squires

Actually, it is on my wish list to have an entire "Custom" property facility for Treeviews and Listviews similar to what is already in place for ListBoxes and ComboBoxes. Basically, allow you to do design time configuration.
Paul Squires
PlanetSquires Software

Paul Squires

Rolf - pretty cool little function :)

You could add a third parameter to the format string to indicate column alignment.   ColName1|ColWidth1|ColAlignment1, ColName2|ColWidth2|ColAlignment2, etc...
Paul Squires
PlanetSquires Software

Rolf Brandt

Good idea, Paul! I think I will implement that too.

I had written for myself a couple of Listview functions, and I think I will have a look over them to expand them a little.

Rolf
Rolf Brandt
http://www.rbsoft.eu
http://www.taxifreeware.com
I cook with wine, sometimes I even add it to the food.
(W. C. Fields)

Gary Stout

Quote from: TechSupport on November 13, 2009, 08:44:42 AM
Actually, it is on my wish list to have an entire "Custom" property facility for Treeviews and Listviews similar to what is already in place for ListBoxes and ComboBoxes. Basically, allow you to do design time configuration.

That would be great Paul! I hadn't got to a listbox or combobox yet, but I use quite a bit of those also. This would also be a HUGE benefit to be able to do this at design time. I like the approach that you have used on the statusbar editor and the custom properties for the tab control. It seems like this same approach would be very easy to set listbox and combobox items. I would think that for the listview, you would only allow the header caption, width of the column and how it is justified.

HTH,
Gary

Andy Flowers

I usuall add the code to initialize my ListViews in the WM_Create function of the Form:-

Here is an example:

   FF_LISTVIEW_INSERTCOLUMN HWND_REPAIR_LVIMAGE, 0, "Item ID",     %LVCFMT_LEFT, 135
   FF_LISTVIEW_INSERTCOLUMN HWND_REPAIR_LVIMAGE, 1, "Route No",    %LVCFMT_LEFT, 80
   FF_LISTVIEW_INSERTCOLUMN HWND_REPAIR_LVIMAGE, 2, "Account No.", %LVCFMT_LEFT, 90
   FF_LISTVIEW_INSERTCOLUMN HWND_REPAIR_LVIMAGE, 3, "Ser. No.",    %LVCFMT_LEFT, 80
   FF_LISTVIEW_INSERTCOLUMN HWND_REPAIR_LVIMAGE, 4, "Amount",      %LVCFMT_RIGHT, 95
   FF_LISTVIEW_INSERTCOLUMN HWND_REPAIR_LVIMAGE, 5, "Doc. Type",   %LVCFMT_CENTER, 75
   FF_LISTVIEW_INSERTCOLUMN HWND_REPAIR_LVIMAGE, 6, "Code",        %LVCFMT_CENTER, 45



Gary Stout

Quote from: TechSupport on November 13, 2009, 08:44:42 AM
Actually, it is on my wish list to have an entire "Custom" property facility for Treeviews and Listviews similar to what is already in place for ListBoxes and ComboBoxes. Basically, allow you to do design time configuration.

I mis-read this reply. I thought the listboxes and comboboxes still needed this feature added also. Just re-read this reply and took a look at a combobox custom property. I think that same approach for the listview and treeviews would be GREAT! I don't see how it could be done any easier. WYSIWYG

Will this be done by then end of the day? ;D

Thanks,
Gary

Paul Squires

Quote from: Gary Stout on November 13, 2009, 01:40:03 PM
Will this be done by the end of the day? ;D

It sure will be... as long as you don't specify which day!  :)
Paul Squires
PlanetSquires Software