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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MSFlexGrid

Status
Not open for further replies.

RRAnthon

Programmer
Sep 25, 2005
24
US
Checked the FAQs and came up empty, so if this has been done before, please set me straight.

In a nutshell, I'm using a multi-select list box, the second column in the grid (the data displayed based on the selection in the first column, a combobox). When I select multiple items, I need to add the number of rows selected from the multi-select to the grid.

Updating the grid one record at a time is a piece of cake, it's the multiple one that's got me stumped.

TIA.
 

Let me get it straight - you have a combobox, (multi-select) list box and a MSFlexGrid on the Form in your VB 6.0 app.

If you select 5 items in your listbox, and you store the number 5 in a variable, let's say intNoOfRecs, you can do:
Code:
MSFlexGrid.Rows = MSFlexGrid.Rows + intNoOfRecs
That should give you - if you start with 2 rows - 7 rows in your MSFlexGrid

Have fun.

---- Andy
 
Andy, thanks for jumping on that, and you got most of it right off the bat. The only thing I'm not getting is how to iterate each row. With your response, how do I take the first new row, add it with the selection, then continue until the fifth selection?
 
THIS MAY help

Sub FillGrid()

Dim Frent As Long
Dim Total As Long



Select Case CBOPeriod.ListIndex
Case 0
Frent = Tnt.Rent * 2 ' WEEK
Case Else
Frent = Tnt.Rent
End Select

If PaysGst = True Then
CalcGst Frent, Total
SumIt Frent, Total, Frent
End If
Total = 0

SumIt Frent, Prop.LeaseCost, Total
SumIt Total, Tnt.BondValue, Total
SumIt Total, ECharges, Total



With MSfDue
.Clear
.Redraw = False
.FixedCols = 0
.Cols = 3
.Rows = 1
StrWork = " RENT IN ADVANCE" & vbTab
StrWork = StrWork & Format(Frent / 100, "#,###,##0.00") & vbTab
StrWork = StrWork & "0"
.AddItem StrWork

StrWork = " BOND" & vbTab
StrWork = StrWork & Format(HoldBondValue / 100, "#,###,##0.00") & vbTab
StrWork = StrWork & "0"
.AddItem StrWork

StrWork = " LEASE FEE" & vbTab
StrWork = StrWork & Format(Prop.LeaseCost / 100, "######0.00") & vbTab
StrWork = StrWork & "0"
.AddItem StrWork


For I = 1 To NoExtraCharges
StrWork = Trim(Echarge(I).Adesc) & vbTab
LngTemp = Echarge(I).Rcharge
StrWork = StrWork & Format(LngTemp / 100, "#,###,##0.00") & vbTab
StrWork = StrWork & Format(I, "###")
.AddItem StrWork
Next






StrWork = "TOTAL" & vbTab
StrWork = StrWork & Format(Total / 100, "$#,###,##0.00") & vbTab
StrWork = StrWork & "0"
.AddItem StrWork

I = 0
.TextMatrix(0, I) = "BEING FOR"
.ColWidth(I) = 2800
.ColAlignment(I) = flexAlignRightCenter
I = I + 1

.TextMatrix(0, I) = "AMOUNT PAYABLE"
.ColWidth(I) = 2350
.ColAlignment(I) = flexAlignRightCenter

I = I + 1
.TextMatrix(0, I) = "CH"
.ColWidth(I) = 0
.ColAlignment(I) = flexAlignLeftCenter

' set grid's style
.AllowBigSelection = True
.FillStyle = flexFillRepeat

' make header bold
.Row = 0
.Col = 0
.RowSel = .FixedRows - 1
.ColSel = .Cols - 1
.CellFontBold = True
.CellAlignment = flexAlignCenterCenter
.AllowBigSelection = False
.FillStyle = flexFillSingle
.Redraw = True
.Row = .Rows - 1
.TopRow = .Row
MSfDue.Visible = True
GridUp = True
AddUpECharges
End With

End Sub
 

Wow Peter, that's some example.

Here is mine: place a listbox (List1) on the Form and set its MultiSelect property to 1, place a Command1 and a MSFlexGrid on the Form.

Try this code:
Code:
Option Explicit
Dim i As Integer

Private Sub Form_Load()

For i = 1 To 10
    List1.AddItem "Item No. " & i
Next i
    
With MSFlexGrid1
    .Clear
    .Cols = 1
    .Rows = 2
    .FormatString = "Some Columns name"
    For i = 1 To 5
        .AddItem "Old Item " & i
    Next i
    .RemoveItem (1)
End With

End Sub

Private Sub Command1_Click()

For i = 0 To List1.ListCount - 1
    If List1.Selected(i) = True Then
        MSFlexGrid1.AddItem List1.List(i)
    End If
Next i

End Sub

Initially you will have 10 items in the List1 to choose from (Item No 1 thru 10) and 5 items in the grid (Old Item 1 thru 5)

Make any selection in the List1 and click on the Command1 command button. The selected items from the list will be added to your grid.

Have fun.

---- Andy
 
Wow, thanks guys. Bear with me while I chew this over and see which works for me.

I'll respond soon.
 
Peter,
Yes it does. I'm trying to use Andy's method. Right now the user can select from a combo box a value which sets up the selection criteria for the second column list box. Once the selection(s) are made in the list box in the second column, I need to populate the grid with the first column for all selections and the corresponding selections for the second column.

So far, it looks like I'm heading in the right direction. Modifying Andy's code, I can get the following to work, now it's just a matter of applying it to the app.

If I select Items 1, 3 and 5 from the list and hit the command button, the grid is now populated with three new rows, all column one's with Bob and column two with Item 1, Item 3 and Item 5. (Tried to paste a picture, no go)

Code:
Private Sub Form_Load()

 Dim scolumnone As String, scolumntwo As String
 
For i = 1 To 10
    List1.AddItem "Item No. " & i
Next i
    
With MSFlexGrid1
    .Clear
    .Rows = 2
    .Col = 1
    '.ColSel = .Cols - 1
    .ColWidth(0) = 2000
    .ColWidth(1) = 2000
    
    scolumnone = "Old Item Column One"
    scolumntwo = "Old Item Column Two"
    .FormatString = "First Column Name"
   
    For i = 1 To 5
        .AddItem scolumnone & " " & i & vbTab & scolumntwo & " " & i
    Next i
    .RemoveItem (1)
End With

End Sub

Private Sub Command1_Click()
Dim sFirstColumnNewValue As String

    sFirstColumnNewValue = "Bob"
For i = 0 To List1.ListCount - 1
    If List1.Selected(i) = True Then
        MSFlexGrid1.AddItem sFirstColumnNewValue & vbTab & List1.List(i)
    End If
Next i
End Sub
 
Thanks to everyone for their assistance, I got the issue resolved. It's basically Andy's code with some variation that you can see if you cut and paste into a new form. I had existing indices that I also had to capture and place in the row, although the columns are not consecutive. Works great!
Code:
Private Sub Form_Load()
For i = 1 To 10
    List1.AddItem "Item No. " & i
Next i
    
With MSFlexGrid1
    .Clear
    .Rows = 0
    .Col = 1
    .ColSel = .Cols - 1
    .ColWidth(0) = 2000 'artificial key
    .ColWidth(1) = 2000
    .ColWidth(2) = 1000
    .ColWidth(3) = 1000
    .ColWidth(4) = 1000
   
    'no headers
    '.FormatString = "First Column Name"
    
    For i = 1 To 5
        .AddItem "First Column Old Item " & i & vbTab & "Second Column " & i
        
    Next i
    'no header, not needed
    '.RemoveItem (1)
End With

End Sub

Private Sub Command1_Click()
Dim rownumber As Integer

For i = 0 To List1.ListCount - 1
    If List1.Selected(i) = True Then
        
        With MSFlexGrid1
            .AddItem "Bob" & vbTab & List1.List(i) & vbTab
            rownumber = .Rows - 1
            .TextMatrix(rownumber, 4) = "fred"
'
        End With
    End If
Next i
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top