CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Oct 2010
    Posts
    3

    Post FLEXGRID VB6 Problem

    Hi there. Please help me, i am currently making a program right now. Flexgrid is not working properly and i can not figure out how it happened.

    The following are the objects i have in the program: Name (txtName), Student Number (txtStudNo), Add (cmdAdd), Remove (cmdRemove) and FlexGrid (flxCart)

    The following are the codes for Add and Remove
    --------------------------------------------------------------------------
    Private Sub cmdAdd_Click()
    Dim ctr As Integer
    ctr = 1

    While ctr < flxCart.Rows
    If flxCart.TextMatrix(ctr, 2) = txtStudNo.Text Then
    Exit Sub
    End If
    ctr = ctr + 1
    Wend

    flxCart.Refresh
    If flxCart.TextMatrix(1, 1) = "" Then
    flxCart.TextMatrix(flxCart.Rows - 1, 1) = txtName.Text
    flxCart.TextMatrix(flxCart.Rows - 1, 2) = txtStudNo.Text
    ElseIf flxCart.TextMatrix(1, 1) <> "" Then
    flxCart.Rows = flxCart.Rows + 1
    flxCart.TextMatrix(flxCart.Rows - 1, 1) = txtName.Text
    flxCart.TextMatrix(flxCart.Rows - 1, 2) = txtStudNo.Text
    End If
    End Sub
    -----------------------------------------------------------------------------------------------

    Private Sub cmdRemove_Click()
    Dim ans As String

    If flxCart.TextMatrix(flxCart.RowSel, flxCart.ColSel) <> "" Then
    ans = MsgBox("Are you sure you want to delete this reserve records?", vbYesNo, "Library System")
    If ans = vbYes And flxCart.Rows = 2 Then
    flxCart.TextMatrix(1, 1) = ""
    flxCart.TextMatrix(1, 2) = ""
    ElseIf ans = vbYes And flxCart.Rows > 2 Then
    flxCart.TextMatrix(flxCart.RowSel, 1) = ""
    flxCart.TextMatrix(flxCart.RowSel, 2) = ""
    flxCart.RemoveItem (flxCart.Row)
    End If
    End If

    End Sub
    -----------------------------------------------------------------------------------------------

    *flxCart will display Name and Student Number when the user clicks the cmdAdd.
    *Same Student Number will not be added to the flxCart.
    *Once the cmdRemove is click the selected row from the flxCart will be deleted.

    Problem:

    During RUN TIME, assuming I added four(data) to the flexcart (Stud1, Stud2, Stud3, Stud4).
    Then I remove Stud3 to the flxCart. But when i click the cmdAdd for adding the previously deleted record(Stud3) again. The codes for cmdAdd is not working.

    Please help me... thank you.

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

    Re: FLEXGRID VB6 Problem

    Read this article, and look at the code. You are missing a few concepts...
    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
    Oct 2010
    Posts
    3

    Question Re: FLEXGRID VB6 Problem

    Thank you for replying dglienna! But the flex grid is not connected to any database. Flexgrid (flxCart) will only be used for holding the input data (Name and StudNo) during run time. Can you help me, how can I add data(Name and StudNo) from text box(txtName, txtStudNo) to the flex grid when the user click the cmdAdd button. The cmdAdd button will not add the data if the StudNo is already added to the flxCart(flex grid). The cmdRemove button will delete the selected row from the flex grid (flxCart).

    This is my problem, I have noticed that the codes above do not work once the removed data from the flexgrid is to be added once again to the flexgrid. But other input (which is not added and removed from the flex grid) is still working. Does the flexgrid hide the removed selected row only? Does the flexgrid has a memory? How can i erase its memory? without clearing the existing data in the flexgrid?

    Badly needed. thank you...

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

    Re: FLEXGRID VB6 Problem

    Read the article, and download the code. The program adds/changes/deletes records from the TABLE, and the GRID is refreshed when necessary.

    You don't erase a row from the grid. You move the row beneath it UP for each row to delete.
    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
    Jul 2006
    Location
    Germany
    Posts
    3,725

    Re: FLEXGRID VB6 Problem

    Never heard about that.

    You remove a row by removing it. It is then gone and done.

    Code:
    Private Sub btnDelRec_Click()
      mfg.RemoveItem mfg.Row
    End Sub
    Assumed your flexgrid is named mfg, this button's code will erase (remove) the currently selected row from the grid.

  6. #6
    Join Date
    Jul 2006
    Location
    Germany
    Posts
    3,725

    Re: FLEXGRID VB6 Problem

    I have just implemented your add-routine to a test program I already had, and I cannot experience your problem. When I delete an existing record from the middle, it is gone. When I try to add the same information again, it is added no problem to the end of the grid.

    You should try to singlestep through your program and see if your loop, which tests if the entry is already there, runs properly and is not somehow fooled.

  7. #7
    Join Date
    Jul 2006
    Location
    Germany
    Posts
    3,725

    Re: FLEXGRID VB6 Problem

    Oh yes, and btw.:
    In an If statement like you had, you do not need to use ElseIf and repeat the complement of the condition. A simple Else would do fine:
    Code:
    If flxCart.TextMatrix(1, 1) = "" Then
       flxCart.TextMatrix(flxCart.Rows - 1, 1) = txtName.Text
       flxCart.TextMatrix(flxCart.Rows - 1, 2) = txtStudNo.Text
    'ElseIf flxCart.TextMatrix(1, 1) <> "" Then <-- useless. Can use a simple Else
    Else
      flxCart.Rows = flxCart.Rows + 1
      flxCart.TextMatrix(flxCart.Rows - 1, 1) = txtName.Text
      flxCart.TextMatrix(flxCart.Rows - 1, 2) = txtStudNo.Text
    End If

  8. #8
    Join Date
    Oct 2010
    Posts
    3

    Re: FLEXGRID VB6 Problem

    Guys, thank you so much for your help and reply. I figured out why my codes is not working.

    The above codes will not work properly if i am using MSHFlexgrid. I should use simply the MSFlexgrid.

    Thank you.. Have a nice day.

Tags for this Thread

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