B4J Question TableView Column Position

Agnetha

Member
Licensed User
Longtime User
Hello!

I have to set the column positions in TableView (NOT B4x Table) programmaticly, e.g. Col3, Col0, Col1, Col2.
How can i do that programmaticly ?
Thank you!
 

DarkoT

Active Member
Licensed User
Hi,
please, take a look on this example... If you will need help, let me know...


With small modification you can use the same logic with a TableView... Or I can prepare example which will help you to create end solution...
 
Upvote 0

mangojack

Well-Known Member
Licensed User
Longtime User
Based on @Erels example Here ... which saves the column order on app close ... (when user manually reorders columns).

I have slightly modified the code to also programmatically reorder the columns and again save the order for next app run.

In the example this is done via Button click , and in a set new order, so you will have to think of an alternative way to work in with your app.

But it should give you a good insight how you might be able to solve your issue.
 

Attachments

  • TableExampleColumnSort.zip
    3.5 KB · Views: 12
Upvote 0

DarkoT

Active Member
Licensed User
Hello!

I have to set the column positions in TableView (NOT B4x Table) programmaticly, e.g. Col3, Col0, Col1, Col2.
How can i do that programmaticly ?
Thank you!


Or - maybe this will help you... If you need example, I can share this source to you...
 
Upvote 0

mangojack

Well-Known Member
Licensed User
Longtime User
@DarkoT .. the OP is wishing to sort the columns programmatically.
 
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
This should do what you want ( in inline java )

Call it with
B4X:
    ' put cols in order 2,0,1   - with some bad column numbers added too
    Me.as(JavaObject).RunMethod("orderOfCols",Array(TableView1,Array As Int(2,-3,0,1,9)))

B4X:
#if java
import javafx.scene.control.TableView;
import javafx.scene.control.TableColumn;

public static void orderOfCols(TableView tv,int[] order){
    // number of columns in table
    int colcnt = tv.getColumns().size();
    
    // dimension our saved columns
    TableColumn[] cols = new TableColumn[colcnt];
    
    // grab original columns
    for (int a = 0 ; a< colcnt; a++){
        cols[a] = (TableColumn)tv.getColumns().get(a);
    }
    
    // clear the columns in the tableview
    tv.getColumns().clear();

    // insert our saved columns back into tableview in the order we want
    for (int aaa : order){
        // check for valid columns
        if (aaa >colcnt || aaa < 0) continue;
        tv.getColumns().add(cols[aaa]);
    }    
}
#End If
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…