Table - MouseDown event and more

Discussion in 'Code Samples & Tips' started by Erel, Apr 6, 2008.

  1. Erel

    Erel Administrator Staff Member Licensed User

    Using the new Door library it is now possible to improve the Table control.
    With the following code you can add a new event, the MouseDown event.
    The HitTest sub will return the pressed row and column (along with the control's part type).

    With this sub you can find the index of the first visible row (this issue was discussed several times in the forum).

    You should include the door library: http://www.basic4ppc.com/forum/showthread.php?t=2038

    The code is attached.
    Code:
    Sub Globals
        
    End Sub

    Sub App_Start
        Form1.Show
        obj.New1(
    true)
        o.New1(
    false)
        table1.AddCol(cstring,
    "c1",50)
        table1.AddCol(cstring,
    "c2",50)
        table1.AddCol(cstring,
    "c3",50)
        
    For i = 1 To 10
            table1.AddRow(i,i,i)
        
    Next
        SetAlternateRowsColor(
    "Table1",cSilver)
        AddMouseDownEvent(
    "Table1")
        HitTest(
    "Table1",35,30)
    End Sub

    Sub AddMouseDownEvent(TableName)
        obj.FromControl(TableName)
        
    event.New1(obj.Value,"MouseDown")
    End Sub
    Sub event_NewEvent
        o.Value = 
    event.Data
        HitTest(
    "Table1",o.GetProperty("X"),o.GetProperty("Y"))
    End Sub
    Sub HitTest(TableName,x,y)
        obj.FromControl(TableName)
        o.Value = obj.RunMethod3(
    "HitTest",x,"System.Int32",y,"System.Int32")
        
        ListBox1.Clear
        ListBox1.Add(
    "X: " & x & " Y: " & y)
        ListBox1.Add(
    "Row: " & o.GetProperty("Row"))
        ListBox1.Add(
    "Column: " & o.GetProperty("Column"))
        ListBox1.Add(
    "Type: " & o.GetProperty("Type"))
    End Sub

    Sub SetAlternateRowsColor (TableName,Color)
        
    If CPPC Then Return 'devices do not support this method
        obj.FromControl(TableName)
        o.CreateNew(
    "System.Drawing.Color" & o.System_Drawing)
        o.Value = o.RunMethod2(
    "FromArgb",Color,"System.Int32")
        obj.Value = obj.GetProperty(
    "TableStyles")
        obj.Value = obj.GetProperty2(
    "Item",0)
        obj.SetProperty2(
    "AlternatingBackColor", o.Value)
    End Sub
     

    Attached Files:

  2. specci48

    specci48 Well-Known Member Licensed User

    Marvellous tip Erel. :sign0060:
    Remembering some very old threads I think that a lot of "coders" will very pleased by this example.


    specci48
     
Loading...