Solved

Replace msflexgrid column content using listview subitem data

Posted on 2004-08-16
11
432 Views
Last Modified: 2013-12-25
How would i replace data in a column in a msflexgrid with a listview subitem.
For example col 5, row1,row2,row 3 with listviews subitem(4) values on each row.
I dont want to commit the numbers yet to the database, just replace
0
Comment
Question by:zachvaldez
  • 5
  • 5
11 Comments
 
LVL 18

Expert Comment

by:Sethi
ID: 11817188
To access the cells of MSHFlexgrid in columns and rows specified by you...do the following:

MSHFlexgrid1.TextMatrix(1,5) -- This is Row 1 column 5
MSHFlexgrid1.TextMatrix(2,5) -- This is Row 2 column 5
MSHFlexgrid1.TextMatrix(3,5) -- This is Row 3 column 5

0
 

Author Comment

by:zachvaldez
ID: 11817357
That is a good start..

However..
How can the row and col be replaced by a variable? Let say we don't know how many rows in that column need to be replace.
for example at col. 5 - there can be 1 or 5 rows.
Can you show me how to loop thru a listview corresponding to filling in the rows of a column in a msflexgrid.
0
 
LVL 18

Assisted Solution

by:Sethi
Sethi earned 200 total points
ID: 11817411
.Rows and .Cols property return the no. of rows and cols in a grid.

To surf through 5 th column and all rows:

For intLoop=0 to .Rows-1
  msgbox MSHFlexgrid1.TextMatrix(intLoop,5)
Next

You can do the same with columns.
0
 

Author Comment

by:zachvaldez
ID: 11820034
HOw about if I want all subitems in  a listview going to column 5 of teh grid....which X no of rows/
0
 
LVL 18

Accepted Solution

by:
Sethi earned 200 total points
ID: 11820151
Exact code u will have to workout...I will give a relative idea here. You will loop through each item in the Listview like this:

For intLoop = 0 to ListView.ListItems.Count -1
  MshFlexgrid1.textMatrix(intLoop,4)=ListView1.ListItems(intLoop).Text  
Next

This code will put the data in 5th column of the MSHFlexgrid.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:zachvaldez
ID: 11821283
So if there are 2 grid columns from  2 subitems...
0
 
LVL 18

Expert Comment

by:Sethi
ID: 11821564
please post ur code and specify what u have achieved so far and what u were not able to achieve
0
 

Author Comment

by:zachvaldez
ID: 11823935
Error happening: Index out of bounds

Public Sub ReplaceCostPrice()
    Dim intLoop As Integer
    For intLoop = 0 To lstPrice.ListItems.Count - 1
        Insertform.grdEquipData.TextMatrix(intLoop, 7) = lstPrice.ListItems(intLoop).SubItems(3) - when it reaches here
    Next intLoop
End Sub
0
 
LVL 18

Expert Comment

by:Sethi
ID: 11826628
This means that there is no SubItem 3 in your ListView. Which one are you mentioning 3rd sub item or 4th. It it is 3rd then mention 2 here else 3.
0
 
LVL 5

Assisted Solution

by:Z03niE
Z03niE earned 50 total points
ID: 11827818
Or it also possible that the flexgrid doesn't have 3rd row.Are you sure that the listview and flexgrid have the same row/Subitem ?

Public Sub ReplaceCostPrice()
    Dim intLoop As Integer
    For intLoop = 0 To lstPrice.ListItems.Count - 1
    if intLoop < grdEquipData.rows -1 then 'Try adding this line of code to see wether the problem is in the flexgrid
        Insertform.grdEquipData.TextMatrix(intLoop, 7) = lstPrice.ListItems(intLoop).SubItems(3) ' when it reaches here
    end if
    Next intLoop
End Sub
0
 

Author Comment

by:zachvaldez
ID: 11834977
HI,

I tried to work around with it and I was able to put the values in the grid. the code below

Public Sub ReplaceCostPrice()
   Dim intLoop As Integer
   Dim litem As ListItem
   Dim iRow As Integer
   
   Set Insertform = TopMDIChildForm
        For intLoop = 1 To lstPrice.ListItems.Count

        For intLoop = 1 To lstPrice.ListItems.Count
             
              Insertform.grdEquipData.TextMatrix(intLoop, 7) = lstPrice.ListItems(intLoop).SubItems(2)
              Insertform.grdEquipData.TextMatrix(intLoop, 9) = lstPrice.ListItems(intLoop).SubItems(3)
         Next
        intLoop = intLoop + 1

However, it is not hitting the proper row.
I have in my listbox line items 1,2,3,4  in a subitemswhich constitute the rows.
In my grid I also have these line items 1,2,3,4 in a cloumn
I only want to replace the col and row of the line item say/ 2,and 4 . What is happening now is that as I execute it. It replaces the 1st and second rows and not the rows I wanted to. It is not finding the correct row basd on the line item #
How can I find the correct rows thru a loop? thru the array... HOw to compare the rows of listbox and grid based on line item #
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
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 Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

746 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now