MSFlexGrid en Visual Basic
klowlead
Posted messages
11
Status
Membre
-
wokerm Posted messages 45 Status Membre -
wokerm Posted messages 45 Status Membre -
Hello everyone (and all)
Could someone explain to me how a Flexgrid works? I know I can do things with the Row, Col, and Text properties, but I don't know how to use them and I'm not familiar with the syntax.
I would like to give titles to my columns and populate each row of the grid with records from a table (using recordset).
If someone could give me some tips, I would be grateful. I am working with VB6.
Thank you.
Could someone explain to me how a Flexgrid works? I know I can do things with the Row, Col, and Text properties, but I don't know how to use them and I'm not familiar with the syntax.
I would like to give titles to my columns and populate each row of the grid with records from a table (using recordset).
If someone could give me some tips, I would be grateful. I am working with VB6.
Thank you.
5 réponses
Hi klowlead,
Here’s perhaps an initial approach to your question:
in the way you placed your MsFlexGrid, by right-clicking on it, set in the properties: the number of rows and the number of columns. Place 1 in the "Fixed row" area.
This fixed row will later serve to indicate the column headers. To populate your headers:
.MaGrid.Clear
.MaGrid.Rows = 1
.MaGrid.Row = .GridAgents.Rows - 1
MaGrid.Col = 0: MaGrid.ColWidth(0) = 2000: MaGrid = "Name"
MaGrid.Col = 1: MaGrid.ColWidth(1) = 2000: MaGrid = "First Name"
MaGrid.Col = 2: MaGrid.ColWidth(2) = 900: MaGrid = "Birth Date"
MaGrid.Col = 3: MaGrid.ColWidth(3) = 1000: MaGrid = "Employer"
MaGrid.Col = 4: MaGrid.ColWidth(4) = 1100: MaGrid = "Health Number"
MaGrid.Col = 5: MaGrid.ColWidth(5) = 3000: MaGrid = "Location"
.......
Then you create your SQL query that allows you to fetch the fields you need to display in your grid.
If Not EOF Then
Do Until EOF
.MaGrid.Rows = .MaGrid.Rows + 1
.MaGrid.Row = .MaGrid.Rows - 1
MaGrid.Col = 0: MaForme.MaGrid = file area (coming from SQL)
MaGrid.Col = 1: MaForme.MaGrid = file area
......
MoveNext
Loop
End If
There you go, try first with these few notes (which I hope are clear enough).
Good luck,
Rudy.
Here’s perhaps an initial approach to your question:
in the way you placed your MsFlexGrid, by right-clicking on it, set in the properties: the number of rows and the number of columns. Place 1 in the "Fixed row" area.
This fixed row will later serve to indicate the column headers. To populate your headers:
.MaGrid.Clear
.MaGrid.Rows = 1
.MaGrid.Row = .GridAgents.Rows - 1
MaGrid.Col = 0: MaGrid.ColWidth(0) = 2000: MaGrid = "Name"
MaGrid.Col = 1: MaGrid.ColWidth(1) = 2000: MaGrid = "First Name"
MaGrid.Col = 2: MaGrid.ColWidth(2) = 900: MaGrid = "Birth Date"
MaGrid.Col = 3: MaGrid.ColWidth(3) = 1000: MaGrid = "Employer"
MaGrid.Col = 4: MaGrid.ColWidth(4) = 1100: MaGrid = "Health Number"
MaGrid.Col = 5: MaGrid.ColWidth(5) = 3000: MaGrid = "Location"
.......
Then you create your SQL query that allows you to fetch the fields you need to display in your grid.
If Not EOF Then
Do Until EOF
.MaGrid.Rows = .MaGrid.Rows + 1
.MaGrid.Row = .MaGrid.Rows - 1
MaGrid.Col = 0: MaForme.MaGrid = file area (coming from SQL)
MaGrid.Col = 1: MaForme.MaGrid = file area
......
MoveNext
Loop
End If
There you go, try first with these few notes (which I hope are clear enough).
Good luck,
Rudy.
Hi Rudy, thanks for your reply. I found what I wanted to do in the meantime. Here’s part of the code I wrote for my application in case it helps someone:
Private Sub Form_Load()
MSFlexGrid1.Cols = 4
MSFlexGrid1.FixedCols = 0
rsSession.MoveFirst
MSFlexGrid1.ColWidth(0) = 1500
MSFlexGrid1.ColWidth(1) = 1500
MSFlexGrid1.ColWidth(2) = 1700
MSFlexGrid1.ColWidth(3) = 1500
MSFlexGrid1.Row = 0
MSFlexGrid1.Text = "Session Code"
MSFlexGrid1.Col = 1
MSFlexGrid1.Row = 0
MSFlexGrid1.Text = "Stage Code"
MSFlexGrid1.Col = 2
MSFlexGrid1.Row = 0
MSFlexGrid1.Text = "Session Date"
MSFlexGrid1.Col = 3
MSFlexGrid1.Row = 0
MSFlexGrid1.Text = "Facilitator"
Do Until rsSession.EOF
MSFlexGrid1.AddItem rsSession("CodeSession") & Chr(9) & rsSession("CodeStage") & Chr(9) & rsSession("DateSession") & Chr(9) & rsSession("NumAnim")
rsSession.MoveNext
Loop
End Sub
Private Sub Form_Load()
MSFlexGrid1.Cols = 4
MSFlexGrid1.FixedCols = 0
rsSession.MoveFirst
MSFlexGrid1.ColWidth(0) = 1500
MSFlexGrid1.ColWidth(1) = 1500
MSFlexGrid1.ColWidth(2) = 1700
MSFlexGrid1.ColWidth(3) = 1500
MSFlexGrid1.Row = 0
MSFlexGrid1.Text = "Session Code"
MSFlexGrid1.Col = 1
MSFlexGrid1.Row = 0
MSFlexGrid1.Text = "Stage Code"
MSFlexGrid1.Col = 2
MSFlexGrid1.Row = 0
MSFlexGrid1.Text = "Session Date"
MSFlexGrid1.Col = 3
MSFlexGrid1.Row = 0
MSFlexGrid1.Text = "Facilitator"
Do Until rsSession.EOF
MSFlexGrid1.AddItem rsSession("CodeSession") & Chr(9) & rsSession("CodeStage") & Chr(9) & rsSession("DateSession") & Chr(9) & rsSession("NumAnim")
rsSession.MoveNext
Loop
End Sub
Hello,
I have an MSFlexGrid and I fill it with a ListBox where I assign my data.
I have a problem; I want to know if it is possible to save the elements of an MSFlexGrid into a database with the event of a button, for example. I have already tried but it doesn't work. I don't know if it's possible or not????
Thank you
I have an MSFlexGrid and I fill it with a ListBox where I assign my data.
I have a problem; I want to know if it is possible to save the elements of an MSFlexGrid into a database with the event of a button, for example. I have already tried but it doesn't work. I don't know if it's possible or not????
Thank you
Salut, je veux de l'aide concernant mon msflexgrid. Je veux qu'après avoir saisi dans une cellule, lorsque je tape sur entrer, le pointeur se déplace automatiquement à la ligne suivante.
As far as I'm concerned, I proceed as follows
suppose I have a table with 05 columns and 04 rows
the column titles must contain the following values
Maths physics sciences chemistry
to fill in the first row starting from the second cell
I do as follows:
.col=1
.row=0
.colsel=4
.row=0
.clip="Maths" & vbtab & "physics" & vbtab & "sciences" & vbtab & "chemistry"
to fill in the titles of the first column
.col=0
.row=1
.col=0
.row=3
.clip="mohamed" & vbcr & "magali" & vbcr & "ludi"
suppose I have a table with 05 columns and 04 rows
the column titles must contain the following values
Maths physics sciences chemistry
to fill in the first row starting from the second cell
I do as follows:
.col=1
.row=0
.colsel=4
.row=0
.clip="Maths" & vbtab & "physics" & vbtab & "sciences" & vbtab & "chemistry"
to fill in the titles of the first column
.col=0
.row=1
.col=0
.row=3
.clip="mohamed" & vbcr & "magali" & vbcr & "ludi"
if you want to calculate the sum of the data in the first column of your MSFlexGrid
for i=1 to MSFlexGrid.Rows-1
cel=MSFlexGrid.matrix(i,0)
s=s+cel
next
then s contains the sum.