2 questions on table object

cirollo

Active Member
Licensed User
Longtime User
Hi guys!

just two questions on tables:

1) in a module I create the table in this way:

B4X:
Sub carico_Show
   ' tabella fornitori
   Table1.Clear
   Table1.AddCol(cString, "Codice", 80)
   Table1.ColWidth("Codice") = 80
   Table1.AddCol(cString, "Ragione Sociale", 120)
   Table1.ColWidth("Ragione Sociale") = 120
   Table1.Visible=True

the problem is that if I close this module and reopen it again I get an error regarding the Table1.AddCol because the structure is already defined.
I tried to do Table1.RemoveCol at the close event on the module but It seems not working. So, how can I destroy a table at the close of the module?

2) when I have the table filled with records, I want to choose one row, but the first time I tap on it It gets the focus and not the selection, I need to tap it again to select that record. How can I have the selection on the first tap?

thanks!
regards,
 

mjcoon

Well-Known Member
Licensed User
Hi guys!

just two questions on tables:

1) in a module I create the table in this way:

...
the problem is that if I close this module and reopen it again I get an error regarding the Table1.AddCol because the structure is already defined.
I tried to do Table1.RemoveCol at the close event on the module but It seems not working. So, how can I destroy a table at the close of the module?

2) when I have the table filled with records, I want to choose one row, but the first time I tap on it It gets the focus and not the selection, I need to tap it again to select that record. How can I have the selection on the first tap?

1) I think that, assuming that you are not changing the columns each time you start the module, the best way is to have an Initialize Sub which is called just once. This creates the columns and does not need to do a Clear because the table is empty. Then at every Show event for the form, just do the Clear (and adjust the widths if necessary).

2) This problem has arisen many times, and only happens if the first row is tapped first, because it is assumed already to be selected. So if the table does not initially have the focus then the GotFocus event should allow you to discover the selected row (=0). The alternative, often mentioned, is to have an invisible (width=0) column which is given the selection when the rows are created. Then the user taps on a different, visible, cell and the SelectionChanged event will trigger.

HTH, Mike.
 

cirollo

Active Member
Licensed User
Longtime User
ok....

But the tables are in different modules....

how can I initialize them???
 

mjcoon

Well-Known Member
Licensed User
But the tables are in different modules....

how can I initialize them???

Sorry, I don't understand the problem. If you have multiple modules you must know how to call from your Main module to subs in the other modules. Each module can have a Public Sub Initialize which are called in turn within the App_Start Sub of the Main module.

(That is how I usually arrange programs with multiple modules.)

It would be possible to manipulate the tables directly from the App_Start sub by using the module name prefix for each mention of the table, but that is clumsy and it is better practice to restrict access to a module's controls and objects to code within that module.

Regards, Mike.
 
Top