Welcome! Log In Create A New Profile

Advanced

[WD25] moving a column in a table control

Posted by Stefan B. 
[WD25] moving a column in a table control
June 06, 2023 12:37PM
Hi,

I have a table control with two columns in it that I want to keep together. So if column-a is moved, I would like column-b to be moved right next to it. I now use an Event() with message 533 to find that a column has been moved, although I don't know if this is the best message for that. But it is fired after moving a column.

Then I try to put column-b right next to it. I do that with the code below, but it doesn't seem to work properly.

liColTijd	is int
liColInd	is int

liColTijd = TableColumnSubscript(TABLE_PLANNING,"COL_PL_TIJD",tcpDisplay)
liColInd = TableColumnSubscript(TABLE_PLANNING,"COL_PL_TIJD_IND",tcpDisplay)
TableMoveColumn(TABLE_PLANNING,COL_PL_TIJD_IND,(liColTijd + 1))

Sometimes column-b is moved, but not to the right place, other times column-b is not moved. But if I click the column header again (and release it again) the column moves too. After performing this action twice, the column is usually in the right place. But never immediately after column-a has been moved.
Does anyone have an idea how I can solve this better?

Thanks in advance.

Regards, Stefan
Re: [WD25] moving a column in a table control
June 06, 2023 01:37PM
Hi Stefan,

there is my procedure "ResetColumnConfiguration"

The global procedure ResetColumnConfiguration() adds a function which is not contained in the AAF-menue of a WINDEV standard Table control. The AAF for a Table control allow for moving, resizing, hiding of shown and showing of hidden columns of the Table control. It even stores the current configuration of the columns! Users are lost when trying to get the columns back into the original order, hide/show-status and sizes. We come to the rescue here and introduce a small but powerful procedure which does that all for us (and for our users, of course!). Insert the new procedure as a global procedure - it will be usable for all of the Table controls in your project!

PROCEDURE ResetColumnConfiguration()

TC,TX, TW, TD are int
PopName is string = PopupField()
TN is string

TC = TableCount(PopName,toColumn)

FOR TX = 1 TO TC
TN = TableEnumColumn(PopName,TX)
TableMoveColumn(PopName,TN,TX)
IF {PopName+"."+TN,indControl}..InitialVisible = False THEN
{PopName+"."+TN,indControl}..Visible = False
ELSE
{PopName+"."+TN,indControl}..Visible = True
END
END

FOR TX = 1 TO TC
TN = TableEnumColumn(PopName,TX)
{PopName+"."+TN,indControl}..Width = {PopName+"."+TN,indControl}..InitialWidth
IF {PopName+"."+TN,indControl}..Visible = True THEN
TW += {PopName+"."+TN,indControl}..Width
END
END

TD = {PopName,indControl}..Width - TW - 18 // 18 ~= Width of vertical scrollbar of Table
FOR TX = 1 TO TC
TN = TableEnumColumn(PopName,TX)
{PopName+"."+TN,indControl}..Width += TD * {PopName+"."+TN,indControl}..AnchorRateWidth / 1000
END

RETURN


Please note:

1) Width of the scroll-bar. Since there's still no function in WINDEV for retrieving the width of the vertical scrollbar (it depends on the chosen style), we assume the mostly found width of 18 pixels in this procedure. But feel free to change the width in this procedure if the style of your Tables demands it.

2) Important: this procedure will ONLY be able to restore the column configuration of a Table control if the sum of the anchoring of all of the columns is 100%!!

Kind regards,
Guenter Predl
office@windev.at
Re: [WD25] moving a column in a table control
June 08, 2023 01:29AM
Did you try to wait for 0.5 seconds after the first column moves? maybe you are trying to move the second column too soon.
Re: [WD25] moving a column in a table control
June 08, 2023 07:54AM
Hi Josegarrido2,

I did indeed try different waiting times at different times, but that didn't really have much effect.

Regards, Stefan
Re: [WD25] moving a column in a table control
June 08, 2023 07:59AM
Guenter,

thanks for your comment. Unfortunately, this is not the solution to the problem. It involves moving a column directly behind another column which produces strange effects. I do use the same commands as in your move procedure, TableEnumColumn() and TableMoveColumn().

Regards, Stefan
Re: [WD25] moving a column in a table control
June 08, 2023 10:25AM
Hi. I did a try and managed to got it working

The problem for me was that the event 533 fired BEFORE the first column moved.
so TableColumnIndex() did return the index before the column moved.

Maybe there are better ways to solve this, but this is how I did:

1. I captured the 533 event normaly from the window initialization process.

Event(proc_movecol,"TABLE_tarifa",533)

2. Created the procedure, proc_movecol, with only one line of code:

proc_movecolumndelayed()

3. Create the procedure proc_movecolumndelayed with the code:

ncolumn1 is int = TableColumnIndex(TABLE_tarifa,"col_item3",tcpDisplay)
nColumn2 is int = ncolumn1+1
Trace(ncolumn1)
TableMoveColumn(TABLE_tarifa,"col_item4",nColumn2)

4. Opened the "automated procedure mechanism" window for the procedure proc_movecolumndelayed.
Set it to "Timer/Scheduler" and set 0.5 seconds delayed in the option "WHEN?"



Edited 2 time(s). Last edit at 06/08/2023 04:09PM by Josegarrido2.
Re: [WD25] moving a column in a table control
June 12, 2023 03:26PM
Hi Josegarrido2,

I have now executed it in the same way as you described, so in the event code only the call of a procedure and given that procedure from the "automated procedure mechanism" a delay of 30 seconds and that works beautifully!

So thank you very much for this work-around.

Regards, Stefan
Author:

Your Email:


Subject:


Spam prevention:
Please, enter the code that you see below in the input field. This is for blocking bots that try to post this form automatically. If the code is hard to read, then just try to guess it right. If you enter the wrong code, a new image is created and you get another chance to enter it right.
Message: