Table Control

harry5568

Member
Dear Administrator,
I could not find much help in the manual regarding use of Table control(or did I miss out on something!!).
Only help available are the source codes submitted by a few members.
For a newbie like me, is it possible to send-in info regarding complete use of the Table control,i.e it's creation,putting in data,data manipulation and its retrieval.
Thanx in advance...Harry :sign0163:
 

harry5568

Member
My Specific requirement is as follows:
To make a 12x12 table with column headers as 50,52,54,56,58,60,62,64,66,68,70,72
row headers as 290,300,310,320,330,340,350,360,370,380,390.
A portion of table looks like:
50 52 54 56 58 60
290 -5 -3 -3 -5 -2 -1
300 2 3 4 3 1 6
310 2 1 8 1 9 0
320 6 2 5 1 8 2
330 1 4 1 5 1 0
340 9 1 0 1 7 8
Firstly, how do i create this table via table control without using csv/xml??
Secondly,how do i add/remove row/column headers and other data??
Thirdly,with reference from two combo boxes on the form,one giving column input and other giving the row input, how do I display the result in a textbox/label.For e.g,if one combobox gives input as 58 and other combobox as 320, how will textbox/label indicate 8,taking reference from the above table??
I'm sure its very simple for most of you.Will be very grateful for your replies.
Harry
 

harry5568

Member
Erel,
Thanks. I know that tutorial exists.If you could find time, please address my specific req as mentioned above,esp the third one,i.e
"Thirdly,with reference from two combo boxes on the form,one giving column input and other giving the row input, how do I display the result in a textbox/label.For e.g,if one combobox gives input as 58 and other combobox as 320, how will textbox/label indicate 8,taking reference from the above table??"
Thx...Harry
 

mjcoon

Well-Known Member
Licensed User
For e.g, if one combobox gives input as 58 and other combobox as 320, how will textbox/label indicate 8,taking reference from the above table??"

I think that the basic choices are to have a visible table, in which case the cell you want would be displayed (with automatic scrolling of the whole table in the visible area) if you set the row and column to be "selected" using Table.SelectCell(). Or to have the table invisible as a hidden storage mechanism and extract the data from the cell chosen via your combo boxes using Table.Cell().

Whether you need a Save...() or Load...() depends on how the data is going to get into your table and whether you wish to retain any edits made to it.

HTH, Mike.
 

harry5568

Member
How many rows will you have in your table? If the table is not too large we can use a simpler approach.
Hi Erel...The table has 12 rows and 12 columns.I don't intend changing the data in the table once it is filled-in. The data in the table is for reference only and will appear in the text-box when called for.
Thanx...I sound like such a layman amongst you guys:BangHead:...Harry
 

harry5568

Member

harry5568

Member
Whether you need a Save...() or Load...() depends on how the data is going to get into your table and whether you wish to retain any edits made to it.
hi mj..a very basic question...does the table have to be created everytime the program would run even if we just use the table for reference, OR would i have to everytime save it as a csv file...i mean ..won't the table stay permanently in the default memory of the table control??
I may be sounding stupid.Thanx...Harry:sign0144:
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
I've attached a small program which will help you get started.
B4X:
Sub Globals
    'Declare the global variables here.

End Sub

Sub App_Start
    Form1.Show
    For col = 50 To 72 Step 2
        table1.AddCol(cNumber, col, 20)
    Next
    table1.ColWidth("50") = 40
    table1.AddRow(290, -5,-3) 'add the other values
    table1.AddRow(300, 2, 3)
    table1.AddRow(310, 2, 1)
    table1.AddRow(320, 6, 2)
    'fill the comboboxes
    For i = 0 To table1.ColCount - 1
        cmbCol.Add(table1.ColName(i))
    Next
    For i = 0 To table1.RowCount - 1
        cmbRow.Add(table1.Cell(50, i))
    Next
End Sub

Sub cmbCol_SelectionChanged (Index, Value)
    UpdateLabel
End Sub
Sub cmbRow_SelectionChanged (Index, Value)
    UpdateLabel
End Sub
Sub UpdateLabel
    If cmbCol.SelectedIndex = -1 OR cmbRow.SelectedIndex = -1 Then Return
    col = cmbCol.Item(cmbCol.SelectedIndex)
    rowValue = cmbRow.Item(cmbRow.SelectedIndex)
    For i = 0 To table1.RowCount - 1
        If table1.Cell("50", i) = rowValue Then
            row = i
            Exit 'exits the for loop
        End If
    Next
    label1.Text = table1.Cell(col, row)
End Sub
 

Attachments

  • 1.sbp
    1.5 KB · Views: 203

harry5568

Member
amazing, fabulous,mindblowing.....3 cheers for you erel.. u're an angel...m glad u cud spare some time for me...i haven't gone through it yet..i'll ask u any doubts later:sign0188::sign0098::sign0142::sign0060:
harry
 

harry5568

Member
Erel...seriously..On Second LOOK...this is what I Xactly Wanted...basic4ppc ROCKS!!! Very Many Thanks indeed:D i can take erel for a joyride in my cockpit on a320...he's a good man:sign0188:harry
 

klaus

Expert
Licensed User
Longtime User
Hi Harry,

As the values in your table are always the same you don't need a table control. You could easily use a two dimension array variable.
With the combobox indexes you get the array variable indexes and you can display the desired value.

Attached a small example program.
The values are initialized directly in the code, but this could also be done in a file and loading this one at the beginning of the program.

Best regards.
 

Attachments

  • TableHarry.sbp
    3.8 KB · Views: 180

Caravelle

Active Member
Licensed User
Longtime User
i can take erel for a joyride in my cockpit on a320

Whose cockpit would that be? People who can afford Airbus A320s don't usually write their own programs!

Caravelle
 

harry5568

Member
Whose cockpit would that be? People who can afford Airbus A320s don't usually write their own programs!

Caravelle
hehe...the cockpit of the a320 i fly for my company belongs to me when i fly it..
asfaras writing own programs is concerned, one doesen't have to have tonnes of money to stop programming,or qualify as a pauper and then start programming:icon_clap:
 

nl1007

Member
Licensed User
Longtime User
I've attached a small program which will help you get started.
B4X:
...
    For i = 0 To table1.RowCount - 1
        cmbRow.Add(table1.Cell(50, i))
    Next
End Sub

...

Sub UpdateLabel
    If cmbCol.SelectedIndex = -1 OR cmbRow.SelectedIndex = -1 Then Return
    col = cmbCol.Item(cmbCol.SelectedIndex)
    rowValue = cmbRow.Item(cmbRow.SelectedIndex)
    For i = 0 To table1.RowCount - 1
        If table1.Cell("50", i) = rowValue Then
            row = i
            Exit 'exits the for loop
        End If
    Next
    label1.Text = table1.Cell(col, row)
End Sub

Since the Combo 'cmbRow' is filled from the table, surely cmbRow.SelectedIndex is the row number? You don't need to look for the text.. (row=cmbRow.SelectedIndex), skip the For..Next block.
 
Top