Questions about LISTBOXes

Hey guys

I have a few issues/questions regarding ListBoxes. I have to admit it is an element I never worked with before so I need a few pointers,

In the software I am working on, I read a tabulated text file and fill a ListBox with that data. It has about 50 columns and at least 100 lines. Now for my questions:

  • Is there a way to set all columns width with one command instead of looping through each of them
  • Same question but with Sortable/NotSortable
  • I also tried to find a way to put color in the headers but could not find anything… Anyway to do it? What about color in the columns?
  • Also, when I filled the headers, I see the first 10 columns as they should, the 11th header is just about 10 pixels wide, and then, the next column header is the last item. But when I mouse over the headers, the missing one appears where they should… Any ideas why?

Thanks for any insight you can provide

Rick

Sure. Use the ListBox.ColumnWidths property. Just set it to a string containing the widths for each column.

No.

Again, no for a global action. For the cells, you’d need to set the ForeColor and use the CellBackgroundPaint event to color the rect.

A couple of ideas here. When you specified the columns have you given all of them a default size? If the total is more than the width of the listbox, is the horizontal scrollbar enabled? If not, the system may try to fit all of the columns in by reducing the sizes of the later columns.

If you don’t need to resize columns (well it’s more work if you do) use the top row for the headers. Listbox.ScrollPosition has the current top row…

So in CellbackgroundPaint:
If row = me.ScrollPosition Then
’ draw whatever background you want
End IF
Return True

In CellTextPaint:

If row = me.ScrollPosition Then
’ format however you want
g.DrawString Cell(row,column), X,y
End IF
Return True.

Of course you are then responsible for positioning the text and a few other details but that should get you started.

  • Karen

Thanks for the ideas, I will look at them