[RESOLVED] Fill MSHFlexGrid using textbox
i able to fill one row of MSHFlexGrid form 6 textbox which i
assinged one by one. The problem is how to fill the next row coz
i want to fill about 100 row into my MSHFlexGrid form the same 6
textbox. Every time i add it will change the first row. I want
it to fill the next row. below is my coding:
Code:
Private Sub cmdAdd_Click()
Dim Iloop3 As Long
Dim R
Dim i As Integer
With MSHF2
.AddItem ""
.TextMatrix(.Row, 1) = txtMembership.Text
.TextMatrix(.Row, 2) = txtNamemem.Text
.TextMatrix(.Row, 3) = txtSandp.Text
.TextMatrix(.Row, 4) = txtNetprice.Text
.TextMatrix(.Row, 5) = txtStatus.Text
.TextMatrix(.Row, 6) = txtPremium.Text
End With
For Iloop3 = 0 To MSHF2.Rows - 1
MSHF2.TextMatrix(R, 0) = R
R = R + 1
Next
End Sub
Re: Fill MSHFlexGrid using textbox
You need to use a STATIC variable.
EDIT: you might want .MouseRow and .MouseCol for your grid.
Code:
Option Explicit
Private Sub Form_Load()
Static I As Integer ' doesn't get set back to 0 each time!
End Sub
Re: Fill MSHFlexGrid using textbox
means, i replace the .textmatrix with .MouseCol and .MouseRow? Hows that, i never use these properties before.
Re: Fill MSHFlexGrid using textbox
They show you where the user clicked. You don't need both. You don't even need them to reload. Just use R (for ROW) like I said.
Don't use a loop. Just update each of R's col's ONCE
Code:
.TextMatrix(R, 1) = txtMembership.Text
Re: Fill MSHFlexGrid using textbox
I don't get it Mr.David.
The loop i put there is for the column 0 numbering. Do you mean i need to take out the With ?
Re: Fill MSHFlexGrid using textbox
This is what I mean:
Code:
Private Sub cmdAdd_Click()
Dim Iloop3 As Long
Static R
Dim i As Integer
With MSHF2
.AddItem ""
.TextMatrix(R, 0) = R ' might want to use R + 1
.TextMatrix(R, 1) = txtMembership.Text
.TextMatrix(R, 2) = txtNamemem.Text
.TextMatrix(R, 3) = txtSandp.Text
.TextMatrix(R, 4) = txtNetprice.Text
.TextMatrix(R, 5) = txtStatus.Text
.TextMatrix(R, 6) = txtPremium.Text
End With
R = R + 1
End Sub
Re: Fill MSHFlexGrid using textbox
I have tried that befor Mr.David. It still just update the first row and adding blank grid after the next add button click. Bellow is the whole coding of my project
Code:
Option Explicit
Private Sub cmdAdd_Click()
Dim Iloop3 As Long
Static R
With MSHF2
.AddItem ""
.TextMatrix(.Row, 0) = R
.TextMatrix(.Row, 1) = txtMembership.Text
.TextMatrix(.Row, 2) = txtPkg.Text
.TextMatrix(.Row, 3) = txtNamemem.Text
.TextMatrix(.Row, 4) = txtSandp.Text
.TextMatrix(.Row, 5) = txtNetprice.Text
.TextMatrix(.Row, 6) = txtStatus.Text
.TextMatrix(.Row, 7) = txtPremium.Text
.TextMatrix(.Row, 8) = txtMemid.Text
End With
R = R + 1
End Sub
Private Sub cmdBatch_Click()
Newbatch.Show
End Sub
Private Sub cmdexit_Click()
Unload Me
End Sub
Private Sub Form_Load()
Set cn = New ADODB.Connection
cn.Provider = "Microsoft.JET.OLEDB.4.0"
cn.ConnectionString = "Data Source = " & App.Path & "\BVCpbschm.mdb;" & "Persist Security Info = False"
cn.Open
MSHF1.ColWidth(0) = 200 'tepi
MSHF1.ColWidth(1) = 1500 'membership
MSHF1.ColWidth(2) = 200 'pkg
MSHF1.ColWidth(3) = 4000 'member name
MSHF1.ColWidth(4) = 1200 'sandp
MSHF1.ColWidth(5) = 900 'net price
MSHF1.ColWidth(6) = 1000 'status
MSHF1.ColWidth(7) = 1000 'status
MSHF2.ColWidth(0) = 500 'tepi
MSHF2.ColWidth(1) = 1500 'membership
MSHF2.ColWidth(2) = 200 'pkg
MSHF2.ColWidth(3) = 4000 'member name
MSHF2.ColWidth(4) = 1200 'sandp
MSHF2.ColWidth(5) = 900 'net price
MSHF2.ColWidth(6) = 1000 'status
MSHF2.ColWidth(7) = 1000 'premium
MSHF2.ColWidth(8) = 1000 'status
Combo1.AddItem "ESTEEM"
Combo1.AddItem "EXECUTIVE"
txtMembership.Enabled = False
txtPkg.Enabled = False
txtNamemem.Enabled = False
txtSandp.Enabled = False
txtNetprice.Enabled = False 'textbox control
txtStatus.Enabled = False
txtPremium.Enabled = True
End Sub
Private Sub MSHF1_Click()
If MSHF1 = "" Then
Exit Sub
Else
txtMembership.Text = MSHF1.TextMatrix(MSHF1.Row, 1)
txtPkg.Text = MSHF1.TextMatrix(MSHF1.Row, 2)
txtNamemem.Text = MSHF1.TextMatrix(MSHF1.Row, 3)
txtSandp.Text = MSHF1.TextMatrix(MSHF1.Row, 4)
txtNetprice.Text = MSHF1.TextMatrix(MSHF1.Row, 5)
txtStatus.Text = MSHF1.TextMatrix(MSHF1.Row, 6)
txtMemid.Text = MSHF1.TextMatrix(MSHF1.Row, 7)
txtPremium = ""
txtPremium.SetFocus
End If
End Sub
Private Sub Combo1_Click() 'Selecting the Database according the name
MSHF1.Clear
Select Case Combo1.Text
Case "ESTEEM"
Call esteem
Case "EXECUTIVE"
Call executive
End Select
End Sub
Private Sub esteem() 'creating connection for Case Advocaten
Set rs1 = New ADODB.Recordset
rs1.Open "SELECT membership,pkg,namemem,sandp,netprice,status,memberid FROM allmship WHERE (package='esteem')", cn, adOpenStatic, adLockPessimistic
Set MSHF1.DataSource = rs1
End Sub
Private Sub executive() 'creating connection for Case Advocaten
Set rs1 = New ADODB.Recordset
rs1.Open "SELECT membership,pkg,namemem,sandp,netprice,status,memberid FROM allmship WHERE (package='executive')", cn, adOpenStatic, adLockPessimistic
Set MSHF1.DataSource = rs1
End Sub
Re: Fill MSHFlexGrid using textbox
The cursor is on .ROW. (not R like we set)
Code:
.TextMatrix(R, 8) = txtMemid.Text
change them all, btw
Re: Fill MSHFlexGrid using textbox
Thank you David.
I fix the coding and my grid property and it work.
Code:
Private Sub cmdAdd_Click()
Dim Iloop3 As Long
Static R
With MSHF2
.AddItem ""
.TextMatrix(R, 1) = txtMembership.Text
.TextMatrix(R, 2) = txtPkg.Text
.TextMatrix(R, 3) = txtNamemem.Text
.TextMatrix(R, 4) = txtSandp.Text
.TextMatrix(R, 5) = txtNetprice.Text
.TextMatrix(R, 6) = txtStatus.Text
.TextMatrix(R, 7) = txtPremium.Text
.TextMatrix(R, 8) = txtMemid.Text
R = R + 1
End With
End Sub
Re: Fill MSHFlexGrid using textbox
Quote:
Originally Posted by
sansann
Thank you David.
I fix the coding and my grid property and it work.
Code:
Private Sub cmdAdd_Click()
Dim Iloop3 As Long
Static R
With MSHF2
.AddItem ""
.TextMatrix(R, 1) = txtMembership.Text
.TextMatrix(R, 2) = txtPkg.Text
.TextMatrix(R, 3) = txtNamemem.Text
.TextMatrix(R, 4) = txtSandp.Text
.TextMatrix(R, 5) = txtNetprice.Text
.TextMatrix(R, 6) = txtStatus.Text
.TextMatrix(R, 7) = txtPremium.Text
.TextMatrix(R, 8) = txtMemid.Text
R = R + 1
End With
End Sub
thanks for the above code, it was very helpful, No.1 site man for learner and beginners just like us . Thanks again to Mr. DAVID
Re: [RESOLVED] Fill MSHFlexGrid using textbox
David is Gr88888888888888
Re: [RESOLVED] Fill MSHFlexGrid using textbox
Yes David is great! :)
Just remember this thread is 2 years old ;)
Keep posting at this wonderful site Registered2009, if you have questions, don't hesitate in posting a New Thread about your topic, and you'll find out how many more great members post here :)