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

MSFlexGrid row increment 1

Status
Not open for further replies.

siokping88

Technical User
Sep 13, 2003
10
0
0
MY
greetings,

i need to know how to move the selected item in a combo box to MSFlexgrid, and each time the combo box is selected with another value, the msflexgrid row will increase by one and the selected item will be displayed in the second row.

any pointer wil be much appreciated

cheers ,
siokping

 

Private Sub Combo1_Click()
MSFlexGrid1.AddItem Combo1.List(Combo1.ListIndex)
MSFlexGrid1.RowPosition(MSFlexGrid1.Rows - 1) = 1
Combo1.RemoveItem (Combo1.ListIndex)
end sub
 
thanks a lot vladk for your reply...

i tried your codes, it works. but the combo1 list is appear in the 1st column. I am supposed to list it in the 4th column. So, how do i modify it?

to make my user convenient, i decided to put a "X" in the first column of each row. If the user wants to delete that particular column, he only needs to click on the first column to delete the whole row.. how do i code it? and after that the following row will replace the deleted row in its current position... how do i move the row?

thanks in advance


 
Code assumes:
1. 1 fixed row and 1 fixed column.
2. "First" column is the first not fixed column.
3. Code will need testing for different grid settings.

Option Explicit

Private Sub Combo1_Click()
MSFlexGrid1.AddItem vbTab & "X" & vbTab & vbTab & Combo1.List(Combo1.ListIndex)
MSFlexGrid1.RowPosition(MSFlexGrid1.Rows - 1) = 1
Combo1.RemoveItem (Combo1.ListIndex)
End Sub

Private Sub MSFlexGrid1_Click()

On Error GoTo ErrorExit

If MSFlexGrid1.Col = 1 Then
MSFlexGrid1.RemoveItem MSFlexGrid1.Row
End If

ErrorExit:

If Err.Number = 30015 Then
Err.Clear
MSFlexGrid1.Rows = 1
End If

End Sub
 
dear vladk,

thanks for your code. i have another question, the code that u have written when adding the data from combo box to flexgrid works. however, the new added data always appear in the first row( that means the first or previous added data will appear at the bottom of the flex grid). If i would like to arrange the previous/first added data in the first row, then only followed by the newly added data in the following rows(that is second row, third row and so on), how do i modify the code?


thanks again! =)
 
Try comment out the following line:

MSFlexGrid1.RowPosition(MSFlexGrid1.Rows - 1) = 1

It was included per your initial request.

 

dear vladk,

i have fixed the fixedrow = 1 and the fixedcol = 1
i have altogether 7 columns and 2 rows by default.(i must have at least 2 rows because if i set the rows to 2, a message will pop up in the msflexgrid property saying that the fixedrow must at least one less that rows, rite?)

my question is, why do i need to have a fixedcol? what is the usage of keeping the fixedcol when i do not need it ('coz the first column is supposed to be the delete column)?

do i need to set the fixed column width to 0, then only starts with the first column(delete column)?


MSFlexGrid1.ColWidth(0) = 0
MSFlexGrid1.ColWidth(1) = 1200
MSFlexGrid1.ColWidth(2) = 1200
MSFlexGrid1.ColWidth(3) = 5200
MSFlexGrid1.ColWidth(4) = 2000
MSFlexGrid1.ColWidth(5) = 2000
MSFlexGrid1.ColWidth(6) = 2000
MSFlexGrid1.TextArray(0) = ""
MSFlexGrid1.TextArray(1) = "Delete"
MSFlexGrid1.TextArray(2) = "Plan Code"
MSFlexGrid1.TextArray(3) = "Plan Name"
MSFlexGrid1.TextArray(4) = "Term/Age"
MSFlexGrid1.TextArray(5) = "Insured Amount"
MSFlexGrid1.TextArray(6) = "Premium"

and another question is each time i delete a row, the text in the msflexfrid1.col(3) have to be add back into the combo list. how do i do this? i have tried the code, but it does not work well. it only return a blank value into the combo box. how can i fix it?

Private Sub MSFlexGrid1_Click()
Dim currentRow As Integer
Dim content As String

On Error GoTo ErrorExit

currentRow = MSFlexGrid1.Row


If MSFlexGrid1.Col = 0 Then
content = MSFlexGrid1.TextMatrix(currentRow, 2)
MSFlexGrid1.RemoveItem MSFlexGrid1.Row
cboPlan.AddItem content /**to add the deleted insurance plan into the combo box
End If


If MSFlexGrid1.Col = 3 And MSFlexGrid1.TextMatrix(currentRow, 2) = "Whole Life 87" Then
frameWholeLife.Visible = True
frameAllPlanDetails.Visible = False
Else
If MSFlexGrid1.Col = 3 And MSFlexGrid1.TextMatrix(currentRow, 2) = "Endowment" Then
frmQuoteComparison.Show
Else
If MSFlexGrid1.Col = 3 And MSFlexGrid1.TextMatrix(currentRow, 2) = "Term Plan" Then
frmTerm.Show
End If
End If
End If

ErrorExit:

If Err.Number = 30015 Then
Err.Clear
MSFlexGrid1.Rows = 1
End If

End Sub

thanks! =)
 
dear vladk,

i think i have figured out how, it was a silly mistakes.
i should change the col to 3 instead of 2.. keke~

If MSFlexGrid1.Col = 0 Then
content = MSFlexGrid1.TextMatrix(currentRow, 3)
MSFlexGrid1.RemoveItem MSFlexGrid1.Row
cboPlan.AddItem content /**to add the deleted insurance plan into the combo box
End If


anyway, thanks a lot.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top