CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 12 of 12
  1. #1
    Join Date
    May 2007
    Posts
    37

    [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

  2. #2
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    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
    Last edited by dglienna; July 16th, 2007 at 11:13 PM.
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    May 2007
    Posts
    37

    Re: Fill MSHFlexGrid using textbox

    means, i replace the .textmatrix with .MouseCol and .MouseRow? Hows that, i never use these properties before.

  4. #4
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    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
    Last edited by dglienna; July 16th, 2007 at 11:36 PM.
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  5. #5
    Join Date
    May 2007
    Posts
    37

    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 ?

  6. #6
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    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
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  7. #7
    Join Date
    May 2007
    Posts
    37

    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

  8. #8
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    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
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  9. #9
    Join Date
    May 2007
    Posts
    37

    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

  10. #10
    Join Date
    Jul 2009
    Posts
    2

    Thumbs up Re: Fill MSHFlexGrid using textbox

    Quote Originally Posted by sansann View Post
    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

  11. #11
    Join Date
    Jul 2009
    Posts
    2

    Re: [RESOLVED] Fill MSHFlexGrid using textbox

    David is Gr88888888888888

  12. #12
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,283

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured