View Single Post
  #1 (permalink)  
Old 04-06-2008, 06:43 PM
Erel's Avatar
Erel Erel is offline
Administrator
 
Join Date: Apr 2007
Posts: 3,204
Default Table - MouseDown event and more

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: Door library (Beta) - Special library

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
File Type: sbp EnhancedTable.sbp (1.7 KB, 108 views)
Reply With Quote