Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.

Tip of the Day
Language: Visual Basic
Expertise: Beginner
Apr 27, 2000



Application Security Testing: An Integral Part of DevOps

Dynamically Populate MSFlexGrid Control

If you use an MSFlexGrid control to display data returned in an ADO recordset, you can use this code to dynamically populate the grid—including the header row—with the information in the recordset. You need an open ADO recordset named rst and a form containing an MSFlexGrid control named msfGrid:
Dim cln As Field
With msfGrid
	.Rows = 2
	.Cols = rst.Fields.Count  
	'get the number of grid cols
	.FixedRows = 1
	.FixedCols = 0
	.Row = 0
	.Col = 0
	For Each cln In rst.Fields
		.Text = cln.Name  
		'populate header row with names of fields
		If .Col < .Cols - 1 Then .Col = .Col + 1
	Do While Not rst.EOF   
	'loop thru recordset to populate grid
		.Row = rst.AbsolutePosition
		'move to the next row
		.Col = 0   
		'reset ourselves back to column(0)
		For Each cln In rst.Fields
			If Not IsNull(cln.Value) Then
				.Text = Trim(CStr(cln.Value))
				.Text = ""
			End If
			If .Col < .Cols - 1 Then .Col = .Col + 1
		.Rows = .Rows + 1  
		'add a new row to the grid
	.Rows = .Rows - 1   
	'remove the last row because it's blank
	.Row = 0
End With
David George
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date