[Gambas-user] Tableview seems to not accept data
sbungay
sbungay at ...981...
Tue Jun 28 21:51:12 CEST 2005
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.
PUBLIC SUB Button1_Click()
DIM Recordset AS Result
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)
$Recordset = Recordset
PopulateTableView1
ELSE
TextBox1.Text = "Record set returned NULL."
END IF
END IF
END WITH
END
PUBLIC SUB Form_Open()
DBConnection=NEW Connection
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
PUBLIC SUB Form_Resize ()
WITH TableView1
.Height = Form1.Height - (Gridview1.Top + 8)
.Width = Form1.Width - (Gridview1.left * 2)
END WITH
END
More information about the User
mailing list