Listbox ColumnWidths change

Hello

I’m trying to make a listbox have a footer with totals for colums, so I though that using a single row listbox at the bottom would do the trick regarding the columsWidth and ColumnCount changes which need to be ‘synced’.
If you guys think that there is a better way to do that let me know.

I can’t figure out how to detect those changes in the first listbox.
Regarding the columncount, I can fix that in code when I make changes to the first listbox make the second listbox equal.
But I would want to have the second listbox mirror the column widths of the first when the user drags columns around too, and I can’t figure out how to track that.

BTW, Is there a way to create custom events like columnWidthChange and columnCountChange ?

Thanks a lot!

Use a timer or one of the two paint events of the listbox.

Yes. You’ll need to create a subclass of list box and then use that in your layouts instead.

Eli is correct !

So, in CellBackcolorPaint or CellTextPaint, put the code to sync both Listbox widths:

LB_Width_Values = LB_Std.ColumnWidths
LB_Footer.ColumnWidths = LB_Width_Values

For example.

Same for Column Count and maybe doing that in a subclass of Listbox (after all, it is an advice from Greg, so I would follow it !)

check out my custom listbox header class… it can be altered easily to be a footer instead, and it obeys all the listbox events

www.rdS.com/lb_header.zip

Awesome!
Thank you very much, everyone!

[quote=282583:@Emile Schwarz]Eli is correct !

So, in CellBackcolorPaint or CellTextPaint, put the code to sync both Listbox widths:

LB_Width_Values = LB_Std.ColumnWidths
LB_Footer.ColumnWidths = LB_Width_Values

For example.

Same for Column Count and maybe doing that in a subclass of Listbox (after all, it is an advice from Greg, so I would follow it !)[/quote]
Why I cannot use LB_Footer.ColumnWidths = LB_Std.ColumnWidths ?

You can, but how / when this will be fired ?

This idea of the XXXXPaint use is to be able to get/set the withs string. Without that, and beside the use of a Timer, I do not know how to fire the code. I take time to check the documentation (and experiment… a bit) before sending the answer.

Did you check Dave project ?

[quote=282593:@Emile Schwarz]You can, but how / when this will be fired ?

This idea of the XXXXPaint use is to be able to get/set the withs string. Without that, and beside the use of a Timer, I do not know how to fire the code. I take time to check the documentation (and experiment… a bit) before sending the answer.

Did you check Dave project ?[/quote]

Oh, I get that you need the event fired somewhere, I’m using the Cellbackgroundpaint actually.
The question was due to the use of the ‘intermediate’ variable, without it the solution won’t work, that was one of the problems I was having.
So it seems that I I can’t do this:

LB_Footer.ColumnWidths = LB_Std.ColumnWidths

It won’t work, and I don’t understand why.

So I ended up using this:

// Sync columns widths with footer If column = 0 then // avoid asigning values on every single row iteration, I bet there is a better way to handle this Dim cols as string = me.ColumnWidths // create the variable, maybe a window property is a better way to handle this? LB.ColumnWidths = cols // assign the variable to the listbox.columnWidth end if

I tried to use mouse drag events but it didn’t work to avoid going through all the cellpaint events. My main listbox can have hundreds of thousands of rows.

About Dave’s code, yes I did, thanks a lot for that, Dave, I will probably use it, but need time to see how to make it work, in the mean time I’m sticking with the simple listbox.

Thank you all for your help.

The two cell events are only called for the currently visible rows.

Use the CellBackgroundEvent of the top left cell only for the copying of the ColumnWidth value.

Like that:

Event CellBackgroundEvent(g As Graphics, row As Integer, column As Integer) As Boolean If row = Me.ScrollPosition And column = 0 Then Listbox2.ColumnWidths = Me.ColumnWidths End ... End

[quote=282649:@Eli Ott]Like that:

Event CellBackgroundEvent(g As Graphics, row As Integer, column As Integer) As Boolean If row = Me.ScrollPosition And column = 0 Then Listbox2.ColumnWidths = Me.ColumnWidths End ... End[/quote]
Thank you so much, Eli!