Search code examples
datagridvb6recordset

How to dynamically add rows to datagrid in vb6


Set rs = conn.Execute(Statement)  //rs has 6 fields

I want to add the current row of rs, to the DataGrid. How could I do that?

Sample:

DataGrid1.<someFunction (say AddRow)> = <some operations with rs.Fields (say, Str(rs.Fields(0)) & rs.Fields(1) & rs.Fields(2) & Str(rs.Fields(3)) & Str(rs.Fields(4)) & Str(rs.Fields(5))  >;

Solution

  • You can add a new row like this.

    DataGrid1.Rows = DataGrid1.Rows + 1
    

    And columns like this

    DataGrid1.Cols = DataGrid1.Cols + 1
    

    After that you can fill the grid like this.

    DataGrid1.TextMatrix(<row>,<column>) = rs.Fields(0)
    DataGrid1.TextMatrix(<row>,<column+1>) = rs.Fields(1)