Determining the indentation of the first column in a hierarchical Listbox

I need to work around a bug in the Listbox (when clicking on the open/close button of a selected row that’s also editable, then the cell goes into Editing mode instead of toggling the folder’s expansion).

To do that, I am going to intercept such mouse clicks in the Listbox.CellClick event.

The difficulty is to know where the open/close button ends and then editable cell begins.

How does one quickly determine this indentation of a particular row in a hierarchical listbox?

Here’s an example of what I am seeing:

And here’s what happen when one clicks on the triangle left of the “c” text in the cell:

I had to do this before and settled on measuring and hard coding the indentation amounts. The first level is 20 something pixels and then each level after that is 12 pixels more.

You might be able to subtract CellTextPaints g.Width from the column width to get it at runtime.

Great solution, Will.

I’ve declared a property: mRowIndent() as Integer

In CellTextPaint I have:

if column = 0 and self.ColumnCount > 0 then if me.ListCount > mRowIndent.Ubound then redim mRowIndent(me.ListCount) end if mRowIndent(row) = me.Column(0).WidthActual - g.Width end if

And in CellClick:

[code] if column = 0 and me.Selected (row) then

dim indent as Integer = mRowIndent(row)
if x < indent then
  // It's left of the editable cell area
  
  if (indent-x) <= 20 then
    // it's within the triangle area
    me.Expanded (row) = not me.Expanded (row)
  end if
  
  return true
end if

end if[/code]

Just add this code after your AddFolder statement(s):

For c As Integer = 0 To Me.ColumnCount - 1 Me.CellType(Me.LastIndex, c) = Listbox.TypeNormal Next
If you have subclassed listbox, just override AddFolder and put the code in there:

Sub Add(item As String) Super.AddFolder(item) For c As Integer = 0 To Me.ColumnCount - 1 Me.CellType(Me.LastIndex, c) = Listbox.TypeNormal Next End Sub

Eli, I think you have not understood my question. You show how to make editable cells non-editable. That’s not the issue here.