Table column header click 2 tables

RB Smissaert

Well-Known Member
Licensed User
Longtime User
I can do a table sort with a table column header click with the Door library fine when there is one table only, but sofar no success when there are 2 tables.
How do I do this? Do I need to add door objects and events for both tables?
I have done that, but the click event is not picked up for the second table.
Thanks for any advice.

RBS
 

RB Smissaert

Well-Known Member
Licensed User
Longtime User
Sub App_Start

DoorObj1.New1(True)
DoorObj2.New1(False)
AddMouseDownEvent("tblPractices")

etc.

Sub AddMouseDownEvent(ControlName)

DoorObj1.FromControl(ControlName)
DoorEvent.New1(DoorObj1.Value, "MouseDown")

End Sub

Sub DoorEvent_NewEvent

Dim strCtrlType

If tblPractices.RowCount = 0 Then Return

DoorObj2.Value = DoorEvent.Data

strCtrlType = GetControlType("tblPractices", _
DoorObj2.GetProperty("X"), _
DoorObj2.GetProperty("Y"))

If strCtrlType = "ColumnHeader" Then
SortTablePractices
End If

End Sub

Sub GetControlType(strControlName, x, y)

DoorObj1.FromControl(strControlName)
DoorObj2.Value = DoorObj1.RunMethod3("HitTest", x, "System.Int32", y, "System.Int32")
Return DoorObj2.GetProperty("Type")

End Sub

Sub SortTablePractices
Dim strSortColName
strSortColName = tblPractices.ColName(DoorObj2.GetProperty("Column"))
Msgbox(strSortColName)
End Sub

This is after going back to code where at least it will work with one table.
There are references to 2 Door objects and 1 Door event.

What I had done before is duplicated all of the above by having refs to 4 Door objects and 2 Door Events and picked the one according to the table.
I am not familiar with .net at all, so I am coding a bit in the dark here.


RBS
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
You need one Event object for each table.
See this code for an example (file is attached):
B4X:
Sub Globals
    'Declare the global variables here.

End Sub

Sub App_Start
    Form1.Show
    table1.AddCol(cNumber,"c1",50)
    table1.AddCol(cNumber,"c2",50)
    table1.AddCol(cNumber,"c3",50)
    For i = 1 To 10
        table1.AddRow(Rnd(0,11), Rnd(0,11), Rnd(0,11))
    Next
    obj.New1(True)
    obj.FromControl("table1")
    event1.New1(obj.Value, "MouseDown")
    
    table2.AddCol(cNumber,"c1",50)
    table2.AddCol(cNumber,"c2",50)
    table2.AddCol(cNumber,"c3",50)
    For i = 1 To 10
        table2.AddRow(Rnd(0,11), Rnd(0,11), Rnd(0,11))
    Next
    obj.FromControl("table2")
    event2.New1(obj.Value, "MouseDown")
    AddEvent("event1", NewEvent, "TableClick_Event")
    AddEvent("event2", NewEvent, "TableClick_Event")
End Sub

Sub TableClick_Event
    Dim strCtrlType
    If Sender = "event1" Then table = "Table1" Else table = "Table2"
    obj.Value = Control(Sender,Event).Data
    strCtrlType = GetControlType("table1", _
                                obj.GetProperty("X"), _
                                obj.GetProperty("Y"))                        
    form1.Text = table & " " & strCtrlType
End Sub

Sub GetControlType(strControlName, x, y)
    obj.FromControl(strControlName)
    obj.Value = obj.RunMethod3("HitTest", x, "System.Int32", y, "System.Int32")
    Return obj.GetProperty("Type")
End Sub
 

Attachments

  • HeadersClick.sbp
    1.5 KB · Views: 157

RB Smissaert

Well-Known Member
Licensed User
Longtime User
All working nicely now and thanks again for clarifying.
One minor thing I noticed is that if you do a table sort on a hidden column then on the desktop the header sorting image will appear on the visible column nearest to that hidden column and that can be confusing. The device doesn't show this image.

RBS
 
Top