How to capture when a listbox column is resized?

I’m looking for the event the will fire when I resize the columns in a listbox. Any hints?

Off the top of my head:

Cache ColumnWidth actual and check in CellBackroundpaint if it has changed… You can also check to see if the Mouse is down… If it is you can calla ColumnResizingEvent. If Mouse is up then fire a columnResizedEvent.

  • Karen

[quote=220130:@Karen Atkocius]Off the top of my head:

Cache ColumnWidth actual and check in CellBackroundpaint if it has changed… You can also check to see if the Mouse is down… If it is you can calla ColumnResizingEvent. If Mouse is up then fire a columnResizedEvent.

  • Karen[/quote]

I already used this method for catching other things changes and I can confirm it works.

Which one? :wink:

Listbox resize, but everything else can be detected. Maybe the weather too. :wink:

Ok Markus, fact is when you delete a post it’s too late, the email notification already started. :stuck_out_tongue:

Btw you are right, I was referring to the first proposal: detecting in CellBackgroundPaint.

Yeah, but I was wrong. After re-reading it is just ONE proposal. The check if the mouse is down happens in the CellBackgroundPaint event.

Maybe I’m close, but I’m a little slow on this technique.

I didn’t find a test of the mouse’s state (though I could do the work and set my own flag, I guess, whenever the mouse button is clicked down or released). But I figured just as good would be to run the test to see if the columns had changed whenever the mouseup is triggered for the listbox.

if me.ColumnWidths <> txtColumn_size.text then
reset_columns
end if

I put this code in the listbox’s MouseUp event, but the MouseUp event is never even called; that’s what surprised me.
Chuck

I forgot to mention that the problem I had using the CellBackgroundPaint event is that as I resize the columns, the event keeps firing until I finally let go of the mouse. I only want to do all of the processing once, when I finish the resizing.

Use a single timer that you reset in the event. When the event stops firing, the timer action happens.

Michel, I’m sorry, that doesn’t mean anything to me. I don’t know what you’re describing.

This is so frustrating that to test something so simple it feels like there’s so much complicated overhead to be added on. and I’ve been finding all kinds of things that don’t work all last night and again all this morning.

@C L: these techniques come with practice. This week I battled with the listbox CellTextPain but in my case the event didn’t fire for the column I needed. So don’t worry.

  • Add a timer to your window or container. Give it a very small period.
  • Add the Action event to your timer and then your code for the resize event.
  • In the resize event set the mode of the timer to ModeOff and then to ModeSingle.

HTH

Hang on. Programming is an exercise in patience.

Beatrix just gave you the tip step by step.

Let’s see if I understand this logic…

  1. I’ll add a timer to the form.
  2. I’ll add a shadow control to the form that has the columnwidth string
  3. In the CellBackgroundPaint event, I know that the object is either being drawn for the first time or being resized.
  4. If the shadow columnwidth <> the listbox columnwidth , then I know the listbox is being resized but I don’t know if the user has completed resizing it because the CellBackgroundPaint event will keep firing as I drag the resize-bar.
  5. I’ll set my timer to fire every second but I’m not sure how it will determine if I’m done resizing. If I’m done resizing, then I’ll call the processing routine and turn the timer’s mode to ModeOff and ModeSingle (I have to look up what those do).

But I still don’t see how the code determines that I’m done resizing.

And this is why I always fill out the Xojo surveys and say that personally love Xojo but I can never recommend Xojo to other developers. It feels like they never go back and improve what they’ve already released. Instead of adding events like a way to capture a resize, they rely on users sharing complicated procedures. Instead of working on my real project because I’ve spent a day trying to resolve basic interface logic.

[quote=221097:@C L Hinkle]Let’s see if I understand this logic…

  1. I’ll add a timer to the form.
  2. I’ll add a shadow control to the form that has the columnwidth string
  3. In the CellBackgroundPaint event, I know that the object is either being drawn for the first time or being resized.
  4. If the shadow columnwidth <> the listbox columnwidth , then I know the listbox is being resized but I don’t know if the user has completed resizing it because the CellBackgroundPaint event will keep firing as I drag the resize-bar.
  5. I’ll set my timer to fire every second but I’m not sure how it will determine if I’m done resizing. If I’m done resizing, then I’ll call the processing routine and turn the timer’s mode to ModeOff and ModeSingle (I have to look up what those do).

But I still don’t see how the code determines that I’m done resizing.
.[/quote]

Instead of bumping the walls in frustration, sometimes it is good to stop and smell the roses.

1 - Add the timer to the window (form) Set it to Off. Period 500 ms. Let’s say it is named Timer1.
2 - In CellBackgroundPaint put this :

Timer1.Mode = Timer.ModeOff Timer1.Mode = Timer.ModeSingle
3 - The timer Action event will fire once, after all the resizing has taken place. Make sure you turn it off there after use :

[code]Sub Action()
MsgBox “Finished”

me.mode = Timer.ModeOff
End Sub
[/code]

Well… a timer seems not to be the most efficient method. Maybe my custom Listbox class will help out.

It uses the CellBackgroundPaint event to update a dictionary with column widths.
When a g.width within that even is different than one stored in the dictionary, it will raise the event. The even definition in my code includes the X (left) position of the column, in relation to the window. This way, you can adjust any controls that needs re-positioning.

1 Like
  1. Cache the Column widths
  2. See if column widths have changed in CellBackgroundpaint
    If No then don’t process and return
  3. Check mouse is down
    If No then cache the new widths, process, then return
    If yes then return without recaching ore processing

Alternatively

  1. Cache the Column widths
  2. See if column widths have changed in CellBackgroundpaint
    If No then don’t process and return
  3. start a timer that checks if mouse is down
    If mouse is up in timer action event Then
    If ColumnWidth changed recache widths , process , stop timer and return
    Else Return and let the timer keep firing

I am struggling with this. Can someone post the code?

Has a feature request been made for a listbox resize event? It would make life easier.