Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Alternative "smarter" datagrid control

Status
Not open for further replies.

toon10

Programmer
Mar 26, 2004
303
DE
Hi

I’m using a treeview control which lists staff members from my database. On the node_click event, I’m populating a datagrid with training record information from a table based on the staff member selected from the treeview. I’m using ADO code to populate a recordset and then setting the datgrid.datasource property to the recordset.

This works fine but the data displayed in the datagrid is a bit messy. Are there any advanced data grid controls out there for VB6 which allow the columns to autofit to the largest data in each column? I’m also looking for “on the fly” sorting by clicking on the column headers.

I know this is a common thing to do but I can’t seem to find any advanced datagrids anywhere that will do the job. My application works but it just doesn’t look good enough to roll out to end users with the standard datagrid.
 
I have found this on the Internet which seems to work well for autosizing if case anyone else wants to do this.

Code:
Public Sub AutoFitColumns()
On Error Resume Next
Dim C As Column, K As Integer, L As Single, Text As String
For Each C In DGresults.Columns 'autofit datagrid columns
    L = TextWidth(C.Caption)
    For K = 0 To DGresults.ApproxCount - 1
        Text = C.CellText(DGresults.RowBookmark(K))
        If TextWidth(Text) > L Then L = TextWidth(Text)
    Next
C.Width = L + 200
Next
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top