Is there a way to dynamic remove the listbox's column

I have 8 columns and need to remove the 5,or 6 sometimes.
depends the requirements,I would like to merge serveral row of the first column.

it may simple…is there any samples? thanks.

There are couple of ways to deal with apparently getting rid of columns…

One is simply setting the width columns you want to 0, so that they are “hidden”

The other way is to actrually change the number of columns on teh fly and move the data around as needed (or just use the paint event)

In terms of merging cells across rows, that is not something that is directly supported by the Xojo listbox, but I sell a listbox subclass that can do that. If interested see:
http://www.katkosoft.com/Mergeable%20Listbox%20Page/MergeableCellListbox.html

I’m not aware of any free solutions to row or column span, but aknother third party solution to consider is DataView

It has a demo project that among other things shows adding or removing columns on the fly, row and column span, etc. But those features just scratch the surface of what it can do. I’ve heard others describe it as magic on steroids.

PS: I’m just a user; I have no vested interest.

To remove the last (or the two last, or…) Row(s), just change the number of columns (ColumnCount).

If you want to remove a Column “anywhere“, use: RemoveRow.

If you…

[quote=332169:@Emile Schwarz]If you want to remove a Column “anywhere“, use: RemoveRow.

[/quote]
sorry Emile, removerow is to remove some row, but not a column …

thanks above replys…
1,I will define my cols number to 50,and hide it when no needs…
2,to merge several row in one column. I would like to draw the cell in cellpaint event… but I still not very sure
how to center the text on the merged row.

I lost my head… Whare is my Head ?

Sorry.

Thanks Jean-Yves.

To remove a Column, I think I start by moving the columns contents to the left, tehn I remove the last column.
(Remove Column 5 of a 8 columns Listbox called LB ? Move Column 6, 7 and 8 to the left, then LB.ListColumn = LB.ListColumn - 1.)

I hope this is correct now.

Is that it on the kitchen counter behind the loaf of bread?

Yes it is… :wink:

[quote=332180:@Chai Ren]thanks above replys…
1,I will define my cols number to 50,and hide it when no needs…
2,to merge several row in one column. I would like to draw the cell in cellpaint event… but I still not very sure
how to center the text on the merged row.[/quote]

Are you talking about vertically centering the text among the pseudo-merged rows/cells?

Assuming you mean the ListBox.CellTextPaint event, consider a few things:

  • The Graphics object you get as part of the event is a single cell (excluding non-text regions like the border or an image etc)
  • You can’t draw outside that single cell using that graphics object
  • CellTextPaint will not fire for cells with no value (you can assign a blank so it fires)
  • Due to various conditions like user scrolling, some of your “merged” row cells may get an event and not others

IMHO, this is one of those wheels that is better to let somebody else invent. Sure, you may be able to there, but if your time is worth anything, you’re (or at least I’m) better served by a third-party control that is royalty-free distribution. And you may find that once available, you can find uses for many of the other features beyond row/column span support. Things like variable row heights, freezing/locking columns on the left, ability to have over 64 columns, zoom scaling, ability for user to re-sequence columns, etc

I originally licensed the control I use specifically because implementing my own row span turned into more work than I wanted to pursue. But I’ve found valuable uses for many other features too. And the developer is responsive to new feature requests.

[quote=332256:@Douglas Handy]The Graphics object you get as part of the event is a single cell (excluding non-text regions like the border or an image etc)
You can’t draw outside that single cell using that graphics object
CellTextPaint will not fire for cells with no value (you can assign a blank so it fires)
Due to various conditions like user scrolling, some of your “merged” row cells may get an event and not others
[/quote]

I can attest it was a lot more work than one would think to get merging cells to work in all situations with the Xojo listbox. It can be be done obviously, as I did it… but it was not fun!

  • Karen

If you pulled it off with a listbox subclass, you had more patience for the nuances then I could justify. Over my decades of programming, I’ve come to realize that just because I could do something, does not mean I should. Xojo has a very impressive feature set on its own. But I license numerous third-party add-ons because the value for the money dwarfs the effort to invent the same wheel. IMHO, this is one of those cases.

[code]Public Sub DeleteColumn(extends alb as Listbox, columnNb as Integer)
’ delete a column from a Listbox
’ moving to the left the columns at the right of the column to delete
’ copies datas from the list, copies the columns,cell and header rowtags
’ columnNb is zero-based

if columnNb<alb.ColumnCount then
for i as Integer = columnNb+1 to alb.ColumnCount-1
for j as Integer = 0 to alb.ListCount-1
alb.Cell(j,i-1) = alb.Cell(j,i)
alb.CellTag(j,i-1) = alb.CellTag(j,i)
next
alb.ColumnTag(i-1) = alb.ColumnTag(i)
alb.Heading(i-1) = alb.Heading(i)
next

alb.ColumnCount = alb.ColumnCount-1

end if

End Sub
[/code]

Jean-Yves: this looks like what I had in mind, and you explained it far better than what I wrote earlier.

I think I did… You can play with it for free in the IDE if want.
It is a subclassed listbox using only Xojo code (only declares are to get the right highlight color) . I had to override almost every listbox method!

Handling all the cases including inserting rows in the middle of cells merged across rows , row highlighting when merged across rows, column resizing, and hierarchical list boxes with connecting lines was rather tedious for sure… As was enabling in cell editing of merged cells (I use an overlaid textField or TextArea) etc etc.

I wrote the first version back in 2010 while I was between jobs and had a lot of time on my hands… Needed something to keep my mind off of financial worries!!!

  • Karen

[quote=332256:@Douglas Handy]Are you talking about vertically centering the text among the pseudo-merged rows/cells?

Assuming you mean the ListBox.CellTextPaint event, consider a few things:

  • The Graphics object you get as part of the event is a single cell (excluding non-text regions like the border or an image etc)
  • You can’t draw outside that single cell using that graphics object
  • CellTextPaint will not fire for cells with no value (you can assign a blank so it fires)
  • Due to various conditions like user scrolling, some of your “merged” row cells may get an event and not others

IMHO, this is one of those wheels that is better to let somebody else invent. Sure, you may be able to there, but if your time is worth anything, you’re (or at least I’m) better served by a third-party control that is royalty-free distribution. And you may find that once available, you can find uses for many of the other features beyond row/column span support. Things like variable row heights, freezing/locking columns on the left, ability to have over 64 columns, zoom scaling, ability for user to re-sequence columns, etc

I originally licensed the control I use specifically because implementing my own row span turned into more work than I wanted to pursue. But I’ve found valuable uses for many other features too. And the developer is responsive to new feature requests.[/quote]

I mean,when I combine /merge the column1(row1,row2,row3) and I need to put a text into the center of merged one.

infact, how I merage that rows is:
use the cellpaint event to draw the boarder of the cell

[quote=332341:@Chai Ren]I mean,when I combine /merge the column1(row1,row2,row3) and I need to put a text into the center of merged one.

infact, how I merage that rows is:
use the cellpaint event to draw the boarder of the cell[/quote]

Are you saying that is what you do now? Or that is what you planned on doing?

My point was that with a standard listbox, it doesn’t know you are spanning cells (horizontal or vertical) and thus the cell paint events happen at the normal cell level. So if you want to merge rows 1, 2, and 3 there would be three separate paint events. Each would be passed a graphics object with the bounds of (only) its own cell. So this complicates drawing text or objects that should flow across the normal cell boundaries.

Computing the proper offsets to draw text centered vertically and / or horizontally is easier when dealing with a single graphics object the size of the merged cells. It gets more complicated when given just a subset at a time, and when only part of the “merged cells” may be visible or otherwise need / get paint events.

With the control I use now, it is built from the ground up on a canvas as the superclass instead of a listbox. So it handles all that for me, as well as being able to handle over 64 columns, variable row heights, and other limitations inherent to the listbox class.

I found a merge solution here:

http://forums.realsoftware.com/viewtopic.php?f=1&t=27957