-
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.
-
Re: FLEXGRID VB6 Problem
Read this article, and look at the code. You are missing a few concepts...
-
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...
-
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.
-
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.
-
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.
-
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
-
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.