Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

mshflexgrid control, programmatically adding data

Posted on 1999-07-28
4
Medium Priority
?
323 Views
Last Modified: 2013-12-25
I would like to programatically add data to a mshflexgrid
control.  I cannot bind the control to my data, because the
data is in a format that will not support binding to the
control. I have two problems.  
First, when I loop through my data structure, assigning
the values to the grid, the first row in my grid
appears empty (the first row below what appears to be
the field name area ... so two rows, really).
Second, I would like to be able to assign field names. I
don't see properties to do that.  Is that only available if
my control is bound?
Here is some code from my procedure:

("theline" is a record from the source data structure)

    Do
        If theline Is Nothing Then
            ' do nothing
        Else
            ' populate a string
            For thecount = 0 To thefields.FieldCount - 1
                    thetabbedline = thetabbedline & vbTab & theline.Value(thecount)
                End If
            Next thecount
            If thetabbedline <> "" Then
            ' add string to grid
                MSFlexGrid1.AddItem thetabbedline
            End If
            thetabbedline = ""
            Set theline = thecursor.NextRow
        End If
    Loop Until theline Is Nothing

It occurs to me that there may be controls better
suited to my goal.  What I need to do is put records
into a grid, be able to identify what rows/columns/
cells are selected by the user, do some sorting,
do some aggregation (sum,mean,etc), export selected
or aggregated records (the least important piece).
If you think that there is another control, that ships
with VB6, Windows NT, or MSOffice2000, that will
better suit my needs, please let me know.

Thanks for your help.
0
Comment
Question by:krouk
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 7

Accepted Solution

by:
simonsabin earned 450 total points
ID: 1495662
I think the easiest way is to have a disconnected recordset and populate that with your data. You can then set the grids datasource to the recordset and heh presto. You can the modify the data using the recordset
0
 

Author Comment

by:krouk
ID: 1495663
Hhmm. Well, I suppose that I could do that ... create a new
ADO recordset, adding my records one at a time, and then assigning that recordset to the control.  However, I
would have the cost of the additional ADO overhead plus,
I would have to write procedures to get data in and of
the recordset structure.  If there was simply a way to
put records into a grid control and specify field names,
that would solve my problem and save me some trouble.
Are you saying that you do not know of a way to do that?
0
 
LVL 7

Expert Comment

by:simonsabin
ID: 1495664
My view is that the stucture and methods available to you as part of an ado recordset are easier to use than those of the flexgrid.
i.e
with adorec
  for lField = 0 to thefields.FieldCount - 1
    .fields.append "field" + cstr(lfield),advarchar
  next
or just
  .fields.append "Value",adlongvarchar
end with

Then you can either store each field or concatenate them as you have and store in the one field.

The current field of the recordset will be that of the grid. so you can easily get the data out.

I prefer that than trying to get round the flexgrids methods  

0
 

Expert Comment

by:Webmeister
ID: 2659599
I experienced the same issues described in the original question. Sure, my data could be bound to a data control - I just despise data controls!

I assume you refer to Column Headings as field names. These are set by using the ColHeaderCaption property as follows...

'Insert headers in grid
For i = 0 To 5
  gridTam.ColHeader(i) = flexColHeaderOn
Next i

With gridObj
  .ColHeaderCaption(0, 0) = "Index"
  .ColHeaderCaption(0, 1) = "Date"
  .ColHeaderCaption(0, 2) = "Time"
  .ColHeaderCaption(0, 3) = "Account"
  .ColHeaderCaption(0, 4) = "Category"
  .ColHeaderCaption(0, 5) = "Activity"
End With

- or -

Add the header line and make it a fixed row:

gridObj.Rows = 2
gridObj.FixedRows = 1
   
gridObj.AddItem "Index" & Chr(9) & "Date" & Chr(9) & "Time" & Chr(9) & "Account" & Chr(9) & "Category" & Chr(9) & "Activity"

I HATE that empty row! After hours of stepping thru the code and trying to understand WHY that empty row keeps showing up, the only way I found to fix it was to use:

RemoveItem(1)  'If .FixedRows = 1
RemoveItem(0)  'If .FixedRows = 0

Put this code AFTER populating the grid with records. This works because the empty row is always the first "non-fixed" row. This is simply a work-around since I have not been able to find any decent instructions on how to effectively use the MSHFlexGrid control. Powerful control, but no docs to be found...

0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Suggested Courses

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question