Member_2_220651
asked on
Load data from SQL server to unbound DBGrid
I have a form for invoice change. The user need to input an invoice no. first, after pressing [Enter] key, the details of the invoice would be shown on an unbound dbgrid. I found that after loading 1 row data, a run-time error "Invalid row number" occured.
The following is my codings.
iRow = 0
SelectLoanItem = "SELECT ItemNo,Description,Serial FROM vwLoanDetailsForIIP "
SelectLoanItem = SelectLoanItem & "WHERE LoanNo = " & CInt(TxtLoanNo)
Set Myrecordset = MyDatabase.OpenRecordset(S electLoanI tem)
Do Until Myrecordset.EOF
DBGridLoanItem.Row = iRow
DBGridLoanItem.Columns(0) = Myrecordset!itemno
DBGridLoanItem.Columns(1) = Myrecordset!Description
DBGridLoanItem.Columns(2) = Myrecordset!Serial
iRow = iRow + 1
Myrecordset.MoveNext
Loop
The following is my codings.
iRow = 0
SelectLoanItem = "SELECT ItemNo,Description,Serial FROM vwLoanDetailsForIIP "
SelectLoanItem = SelectLoanItem & "WHERE LoanNo = " & CInt(TxtLoanNo)
Set Myrecordset = MyDatabase.OpenRecordset(S
Do Until Myrecordset.EOF
DBGridLoanItem.Row = iRow
DBGridLoanItem.Columns(0) = Myrecordset!itemno
DBGridLoanItem.Columns(1) = Myrecordset!Description
DBGridLoanItem.Columns(2) = Myrecordset!Serial
iRow = iRow + 1
Myrecordset.MoveNext
Loop
ASKER
I have tried your proposed answer, however, the effect is the same. "Invalid row number" error still occurs.
I found that it's always successful when I load the first invoice.
The case is that, if I load second which contains more details-line than the first one, this error would occur.(But I have already refresh the grid and reset iRow to 0 before loading details to it)
I found that it's always successful when I load the first invoice.
The case is that, if I load second which contains more details-line than the first one, this error would occur.(But I have already refresh the grid and reset iRow to 0 before loading details to it)
Try setting iRow to 1 instead of 0 (Row 0 is the heading row)
yyjulie,
Make sure that you make clifAbb earn those 5 points. Don't let him get away with just giving you text answers. Insist on lots of code.
Make sure that you make clifAbb earn those 5 points. Don't let him get away with just giving you text answers. Insist on lots of code.
zsi:
C'mon, it's not the points, it's the pleasure in helping.
(Of course, I'm already in the top 15 list.)
;)
C'mon, it's not the points, it's the pleasure in helping.
(Of course, I'm already in the top 15 list.)
;)
Yes, I know. It's all about helping people. blah blah blah.
This is why I always see people fighting each other> It's not over points.
It's their earnest to help people. :)
The soapbox is free now. Next!
hehehe
This is why I always see people fighting each other> It's not over points.
It's their earnest to help people. :)
The soapbox is free now. Next!
hehehe
That's ok, I carry my own personal soapbox where ever I go. :)
ASKER
Hello clifABB,
I have tried to set iRow to 1, but same result.
Moreover, I can't load the first invoice.
I got some comments about the DBGrid of VB5, especially for the unbound one, people say that it's not flexible, and now i am experiencing from it! Really, it's quite diffiult. It's not easy to develop as the table form in SQL Windows. I think their concept is the same.
They suggest me to buy a third-party product such as Apex True Grid. i'm worry about whether it is really easy to use and more powerful than the DBGrid of VB5.
I have tried to set iRow to 1, but same result.
Moreover, I can't load the first invoice.
I got some comments about the DBGrid of VB5, especially for the unbound one, people say that it's not flexible, and now i am experiencing from it! Really, it's quite diffiult. It's not easy to develop as the table form in SQL Windows. I think their concept is the same.
They suggest me to buy a third-party product such as Apex True Grid. i'm worry about whether it is really easy to use and more powerful than the DBGrid of VB5.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
zsi's and clifABB,
Thank you for your helping hands.
Anyway, can someone help me to solve the problem of unbound DBGrid.
Thank you for your helping hands.
Anyway, can someone help me to solve the problem of unbound DBGrid.
Actually, in my opinion, for unbound grid, I much prefer MSFlexGrid. It's actually a product of Videosoft (like DBGrid is a product of Apex), and has a much better interface for working with unbound code.
I've resorted to Farpoint's Spread myself. I needed ComboBoxes as a cell datatype. I coded the whole functionality over the standard VB grid (with textboxes, too), but didn't feel comfortable with the results.
yyjulie:
Are you locked into using DBGrid? If there's not *too* much code behind it, and you don't mind switching, you might consider using MSFlex which also comes with VB.
If you decide on this, let me know and I'll help you with the switch.
Are you locked into using DBGrid? If there's not *too* much code behind it, and you don't mind switching, you might consider using MSFlex which also comes with VB.
If you decide on this, let me know and I'll help you with the switch.
...and if you *do* have a lot of code, Apex's TrueGrid is a 'drop-in' replacement for the dbGrid. Meaining that you will not have to change any of your code.
Or, at least, that's the theory.
Or, at least, that's the theory.
ASKER
I know that MSFlexGrid is suitable for displaying data but it does not allow to make changes in data. Am I right?
You can edit a cell's contents with MSFlexGrid, however it's not quite as straightforward as you might like.
Add A textbox to your form.
Set it's visible property to false.
Set it's BorderStyle to 0 - None
Add the following code to MSFlexGrid's EnterCell event:
Private Sub MSFlexGrid1_EnterCell()
With MSFlexGrid1
Text1.Move .Left + .CellLeft, .Top + .CellTop, .CellWidth, .CellHeight
Text1.Text = .TextMatrix(.Row, .Col)
Text1.Visible = True
Text1.SetFocus
End With
End Sub
Add the following code to MSFlexGrid's LeaveCell event:
Private Sub MSFlexGrid1_LeaveCell()
With MSFlexGrid1
.TextMatrix(.Row, .Col) = Text1.Text
End With
End Sub
Add A textbox to your form.
Set it's visible property to false.
Set it's BorderStyle to 0 - None
Add the following code to MSFlexGrid's EnterCell event:
Private Sub MSFlexGrid1_EnterCell()
With MSFlexGrid1
Text1.Move .Left + .CellLeft, .Top + .CellTop, .CellWidth, .CellHeight
Text1.Text = .TextMatrix(.Row, .Col)
Text1.Visible = True
Text1.SetFocus
End With
End Sub
Add the following code to MSFlexGrid's LeaveCell event:
Private Sub MSFlexGrid1_LeaveCell()
With MSFlexGrid1
.TextMatrix(.Row, .Col) = Text1.Text
End With
End Sub
*danger* Will Robinson *danger*
Don't do it! It seems harmless at first. Just overlay a textbox on the grid. What harm could it do?
Then your users ask for a combo box.
Then they want graphics.
Then they want option buttons and checkboxes and drop-down trees and...
They you are out of hair.
I started down this seemingly innocent path of trying to make the stock grid control do things it wasn't meant to do. I wasted too much time of my life and have since resorted to an editable grid (Spread, warts and all).
Also, a big problem with this method is that you lose a lot of your keyboard navigation. Syncronizing the controls is also a major headache (at least, if you do it right and try to make the whole gamut one big object). The grid control does not always report the proper cell cordinates and on and on.
I am a big fan of minimizing the number of controls used in a project. I prefer to do as much as possible through code. I wholeheartedly support the Common Control Replacement Project (http://www.mvps.org/ccrp). However, when it comes to this control, you will find yourself spending more time working on the control than the project itself.
I normally agree with my esteemed colleague (yeah, right :), but this time I have to take a suggest a different approach.
zsi
Don't do it! It seems harmless at first. Just overlay a textbox on the grid. What harm could it do?
Then your users ask for a combo box.
Then they want graphics.
Then they want option buttons and checkboxes and drop-down trees and...
They you are out of hair.
I started down this seemingly innocent path of trying to make the stock grid control do things it wasn't meant to do. I wasted too much time of my life and have since resorted to an editable grid (Spread, warts and all).
Also, a big problem with this method is that you lose a lot of your keyboard navigation. Syncronizing the controls is also a major headache (at least, if you do it right and try to make the whole gamut one big object). The grid control does not always report the proper cell cordinates and on and on.
I am a big fan of minimizing the number of controls used in a project. I prefer to do as much as possible through code. I wholeheartedly support the Common Control Replacement Project (http://www.mvps.org/ccrp). However, when it comes to this control, you will find yourself spending more time working on the control than the project itself.
I normally agree with my esteemed colleague (yeah, right :), but this time I have to take a suggest a different approach.
zsi
zsi:
You do have a point, I was there as well. However, this is the code that is supplied by VideoSoft (the original developers of the Flex control) for editing their grid.
You do have a point, I was there as well. However, this is the code that is supplied by VideoSoft (the original developers of the Flex control) for editing their grid.
See Above.
:)
:)
ASKER
For both of you, zsi's and clifABB, thank you very much. I really learnt from you. :)
I have decided to use either Apex DBGrid Pro or Spread 2.5.
I have decided to use either Apex DBGrid Pro or Spread 2.5.
Do Until Myrecordset.EOF
If iRow > DBGridLoanItem.Rows Then 'Add these three lines
DBRridLoanItem.Rows = iRow
End If
DBGridLoanItem.Row = iRow
.
.
.