How Do I Do This with a Listbox

Hey gang,

I have a Listbox. In that listbox are some fields that I want to be editable. There’s a couple of checkbox columns and a couple column where when someone clicks on the cell, I open another sort of dialog window where they enter information that then gets entered into the cell when the window is closed. Those fields are to be “non-editable.”

I’d like to be able to tab from column to column in the listbox, but tabbing and getting the “CellGotFocus” event to fire requires that the cell be of type editable. As soon as you make a check box cell editable, it loses the checkbox. I just want the cell to be “selected” so the user can tab through it and decided if they want to check it.

Do I make sense? How can I select a cell or indicate it is selected without having the cell become Listbox.TypeEditable?

Certainly there must be a way to do this…

I would do that by showing a focus ring using CellBackgroundPaint, and keep the focused attribute in CellTag.

That will require some extra code in CellKeydown with the previous column, but it seems quite feasible. Then you need to catch Tab in the ListBox KeyDown, since CellKeyDown is not available as the cell is not actually focused, to tab to the next cell on the row.

Likewise you probably will need to address Return, often used to change the cell state when the cell is focused.

What I do is change it to a single character fast field that accepts Y/N on gotfocus and change it back to a checkbox on lostfocus.

Yeah but I’m wanting the user to be able to check/uncheck the box while the cell has the focus. Not sure what you mean by “fast field”

[quote=305001:@Michel Bujardet]I would do that by showing a focus ring using CellBackgroundPaint, and keep the focused attribute in CellTag.

That will require some extra code in CellKeydown with the previous column, but it seems quite feasible. Then you need to catch Tab in the ListBox KeyDown, since CellKeyDown is not available as the cell is not actually focused, to tab to the next cell on the row.

Likewise you probably will need to address Return, often used to change the cell state when the cell is focused.[/quote]

This is what I was thinking I would need to do. Started messing with some of it. I have all of the mechanics for handing the key downs, return, etc. It was more of just being able to set the focus of the cell. I was hoping there was some “easier” way of doing it that I was not seeing.

[quote=305025:@Jon Ogden]Yeah but I’m wanting the user to be able to check/uncheck the box while the cell has the focus.
[/quote]
I figure if the cell got focus, it was by keyboard action (a mouse click would simply check the box, not give focus) so I don’t want the user to have to take his hands of the keyboard and reach all the way over to the mouse, find the cursor, hover over the cell, and click. Talk about a waste of time/effort. Let him change the value via keyboard.

As soon as the user enters a valid character, it automatically moves to the next cell. I don’t remember if that is built in to the base listbox or if it’s something I added.

You could probably set the checkbox selection itself, but that calls for declares that are probably not that simple since the checkbox is not exposed. Besides, in macOS, the checkbox does not focus unless you set extended keyboard control.

I don’t think that would be “easier” at all.