Sunday, 7 October 2012

MSFlex Grid Operation in VB6.0

MS Flex Grid is a data grid which is use to retrieve records from database.It is very
Flexible, It Accept data run time from vb coding.It is useful for users who
interact database with coding . Coding is more powerful and flexible
than database controls (Data,ADODC).With the help of coding you can
run SQL statement in its original from as we use at command prompt
in oracle.Because Flex grid doesn't configure with database controls .You have
to configure it manually with the help of coding.There is not any row or columns
are predefine its programmer responsibility to make it. take a look on following

  •  MSFlexGrid1
Adding  Module
  • Click Project menu and Add a module
Import Other Classes
  •  Click project menu and select component and  Select Microsoft Flex Grid Control 6.0
  •  Click project menu and select references and select Microsoft ActiveX Data Objects 2.0 Library

My database is in access named bsw and table names is stu(roll,name,city)
Module Code..
Global con As New ADODB.Connection
Global rs As New ADODB.Recordset
Public Sub openco()
    con.Open "provider=microsoft.jet.oledb.4.0;data source=bsw.mdb"
End Sub

Private Sub Form_Load()
    If rs.State Then rs.Close
    rs.Open "select * from stu ", con, adOpenStatic, adLockReadOnly
    Dim r%, c&
    r = 1
    c = 1
    MSFlexGrid1.TextMatrix(0, 0) = "Roll"
    MSFlexGrid1.TextMatrix(0, 1) = "Name"
    MSFlexGrid1.TextMatrix(0, 2) = "City"

    Do While Not rs.EOF
        MSFlexGrid1.TextMatrix(r, 0) = rs.Fields(0)
        MSFlexGrid1.TextMatrix(r, 1) = rs.Fields(1)
        MSFlexGrid1.TextMatrix(r, 2) = rs.Fields(2)
        MSFlexGrid1.Rows = MSFlexGrid1.Rows + 1
        r = r + 1

End Sub

Private Sub MSFlexGrid1_Click()
    MsgBox MSFlexGrid1.TextMatrix(MSFlexGrid1.Row, 0) & vbCrLf &     MSFlexGrid1.TextMatrix(MSFlexGrid1.Row, 1) & vbCrLf & MSFlexGrid1.TextMatrix(MSFlexGrid1.Row, 2)
End Sub

No comments:

Post a comment