[Gambas-user] Tableview seems to not accept data

fabien gambasfr at ...11...
Tue Jun 28 22:29:54 CEST 2005


Le Mardi 28 Juin 2005 21:51, sbungay a écrit :
>    I must be missing something... but it should work. The field names
> appear at the top of the columns... but no data ever appears in the
> cells. This is pretty rough code... sorry... I'm just hacking around to
> see what can be done and what kinds of difficulties I'll run into.
>
> ' Gambas class file
>
> PUBLIC DBConnection AS NEW Connection
>
>
> ' Button 1 executes some SQL and returns the result in a recordset.
PRIVATE Recordset AS Result
 PUBLIC SUB Button1_Click()

    
    Dim i as integer
    WITH DBConnection
         .Type="mysql"
         .Host="localhost"
         .Login="testuser"
         .Password="test"
         .Name="testtable"
         TRY .Open
         IF ERROR THEN
            PRINT "Cannot Open Database. Error=" & Error.Text & "."
         ELSE
            Recordset=.Exec("SELECT * FROM Company;")
            IF Recordset <> NULL THEN
              TextBox1.Text = Recordset.Count & " Records returned."
              'PopulateGrid(Recordset)
              'PopulateTableView(Recordset)
              
              'PopulateTableView1
              TableView1.Columns.Count = RecordSet.Count
              For i = 0 to RecordSet.Count -1
                TableView1.Columns[X].Text = Recordset.fields[X].Name
              Next
 TableView1.Rows.Count = RecordSet.Count

            ELSE
              TextBox1.Text = "Record set returned NULL."
            END IF
         END IF
    END WITH
 END
>
> PUBLIC SUB Form_Open()
>    DBConnection=NEW Connection
> END


PUBLIC SUB TableView1_Data(Row, Column)

  RecordSet.Moveto(Row)
  TableView1.Data.Text = RecordSet[TableView1.Columns(column).text]

END


> PRIVATE SUB PopulateTableView (Recordset AS Result)
>    DIM X AS Integer
>    DIM Y AS Integer
>
>    DIM Rows AS Integer
>    DIM Columns AS Integer
>
>    Columns = Recordset.Fields.Count
>    Rows = Recordset.Count
>
>    TableView1.Columns.Count = Columns
>
>    ' Put up the titles
>    Y = 1
>    FOR X = 0 TO Columns - 1
>      WITH TableView1
>           .Rows.Count=Y
>           .Row = Y
>           .Column = X
>           .Columns[X].Text = Recordset.fields[X].Name
>      END WITH
>    NEXT
>
>    ' Now put in the values
>    ' Recordset starts a row 0.
>    FOR Y = 1 TO Rows
>        TableView1.Rows.Count = Rows + 1
>        TableView1.Row = Y
>        Recordset.MoveTo(Y-1)
>        FOR X = 1 TO Columns - 1
>            WITH TableView1
>                 .Columns = X
>                 .Data.Text = Recordset[Recordset.fields[X].Name]
>            END WITH
>        NEXT
>    NEXT
>
> END
>


You know what ?, gambas have containers :)

try to play with it !
in an empty form put 2 widget, set the form alignment property to horizontal, 
and then set the second widget expand property to true and try it !

it is magic!

in fact for the most of time i never use the _resize event !

the containers have this property :

Alignment
   - None (widjets are not aligned)
   - Horizontal (widgets height property automatiquely set with ClientHeigth 
when resize)
   - Vertical (same thing but for width)
   - Fill (the both)
   - leftRight
   - TopBottom

The widjet have this property

- Expand (the widget fill the empty place)


Fabien


> PUBLIC SUB Form_Resize ()
>
>    WITH TableView1
>         .Height = Form1.Height - (Gridview1.Top + 8)
>         .Width = Form1.Width - (Gridview1.left * 2)
>    END WITH
>
> END
>
>
> -------------------------------------------------------
> SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
> from IBM. Find simple to follow Roadmaps, straightforward articles,
> informative Webcasts and more! Get everything you need to get up to
> speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
> _______________________________________________
> Gambas-user mailing list
> Gambas-user at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-user





More information about the User mailing list