[Gambas-user] 2 little problens

Richard richard.j.walker at ...247...
Tue Apr 17 00:29:45 CEST 2007


On Monday 16 Apr 2007 18:40, Hamilton Geminiano Andrioli Junior wrote:
> Hi guys!
>
> Well, how can I use the Header propertie on a GridView?
> I would like to give a name for the column header!
>

Here's a little program I wrote a few days ago when exploring various ways to 
select rows in a table view. Taking all that out of it leaves this code which 
will work for a simple form with a QUIT button and a table view. It should be 
the same for a grid view I expect, except that a GridView doesn't seem to 
have the "Header" property (which I set to "Both" for the TableView I used).

So, I suggest you use the TableView instead of the GridView and then it as 
easy as this..........

It sets up a 10x10 table and fills it with numbers. The Column headers and row 
labels are filled in by the Form_Open code.


' Gambas class file

' A program to show how to control the highlighting of rows in a TableView 
grid

' Set aside storage for table test data
PRIVATE tabledata AS Integer[10, 10]

' Provide switches to selectively "disable" certain events
PRIVATE NO_CHANGE_EVENT AS Boolean
PRIVATE NO_SELECT_EVENT AS Boolean

PUBLIC SUB _new()

END

PUBLIC SUB Form_Open()
DIM n, m AS Integer

    ' Set up the table size and decorations
    WITH TableView1
        
        'The table size
        .Rows.count = 10
        .Columns.count = 10
        
        'Set column widths
        .Columns[0].width = .Font.Width("First Column")
        .Columns[1].width = .Font.Width("Second Column")
        .Columns[2].width = .Font.Width("Third Column")
        
        'Make the rest of the column widths suit their headers (plus a bit)
        FOR n = 3 TO 9
            .Columns[n].width = .Font.Width("Col " & Str$(n) & "+")
        NEXT 
        
        'Write some column and row labels
        FOR n = 0 TO 9
            .rows[n].Title = Str$(n)
            .Columns[n].title = "Col " & Str$(n)
        NEXT 
        
    END WITH
    
    'Create some test data in the storage array
    FOR n = 0 TO 9
        FOR m = 0 TO 9
            tabledata[n, m] = n * 10 + m
        NEXT 'm
    NEXT 'n
    
    'This should let us avoid unwanted side effects in CHANGE event handlers
    NO_CHANGE_EVENT = FALSE
    'Ditto for SELECT events
    NO_SELECT_EVENT = FALSE

    'Highlight the first row - at least that is what I expect it to do
    tableview1.Rows[0].selected = TRUE
    
    'That didn't work. Try again by setting the SpinBox1 value
    spinbox1.value = 0
    
    'Still doesn't work, but setting the row and spinbox to 1 does the job
    tableview1.Rows[1].selected = TRUE
    spinbox1.value = 1
    
    'Now setting the spinbox back to 0 moves the highlight to the right place
    spinbox1.value = 0
    
END


PUBLIC SUB Button1_Click()

    ME.close  

END

'Draw the table view contents
PUBLIC SUB TableView1_Data(Row AS Integer, Column AS Integer)

    tableview1.Data.text = tabledata[row, column]
    
    'Pretty it up a bit
    tableview1.Data.background = 16777215 - tabledata[row, column]

END




More information about the User mailing list