DataGrid Revisited

dusteater
09-17-2000, 11:55 PM
I have a program where I need the user to input data into a DataGrid. Well I got the Grid to work like I want it to with the exception of one thing, when the user hits "Enter" I want the focus to move down in the column one position and select the data for editing I found a way to move down in the column but I can't find a way to keep the cursor from "falling off the end of the Earth"(moving beyond the end of the grid). Also, I can't get it to Select the data in the next cell. When you type your data you lose the first character. I can work around this if I can simulate the pressing of a key in code.
Any Ideas??
Thanks Rick

Valkyrie
09-18-2000, 09:52 AM
OK...You are running an editable DataGrid. When you press enter the focus moves to the cell on the row below the current row and the cell is in edit mode. You lost me on the part where it falls off the end of the world and the simulated enter key?

If you are on the last row of the grid and you press enter is that when the edit box goes too far or is it something else? If it is the last row you can track that and if Row+1 > Rows then you can skip the move ahead logic. If it is something else lemme know.

Simulating the enter key in debug mode is a simple matter. Create a test sub that calls the code you want to debug, passing the value of the enter key. If you do it in a loop you can repeat as often as you need.

<font color=blue><pre>Private Sub Test()
Dim x as Boolean
x = True
While x
SubYouWantToTest(vbKeyReturn)
Wend
</font color=blue></pre>


You can call your routine as often as you want and then click on Stop on the button bar to stop it!

HTH

Quote of the moment....
"My job is so top secret even I don't know what I'm doing!"

dusteater
09-19-2000, 12:12 PM
The program does not recognize the rows method. It has col and columns method but does not have a rows method so that does not work. I think it might be a program error but how do I fix it... If I reinstall VB will I lose my projects? I know that there must be a way to test for the total number of rows but I can't find it. Also, I guess I wasn't clear on the key press issue. Let me explain. When I trap the "enter" key the cursor moves down to the next row like I want it to but, then the data in the current cell is not selected for editing. When you press any key (except Enter) the Data in the cell becomes selected and is ready to be edited. I would like to have the data selected but if that is not possible I would like to know how to simulate the pressing of a key (like maybe the space bar or a number key) and this would then select the data I hope.

Valkyrie
09-19-2000, 02:51 PM
Sorry Rick...I was thinking of the FlexGrid. For the DBGrid to determine the number of rows use the Recordset object's RecordCount property. For some help on how to use the DBGRID visit http://www.apexsc.com . Personally I haven't used it as my preference goes towards FlexGrid.

You could use the SendKeys command to send a value other than Enter to get youself in Edit mode. I realize it's a kluge but it should work. Ideally you should figure out what event is triggering and then call that after the Enter event.

HTH.




Quote of the moment....
"My job is so top secret even I don't know what I'm doing!"

dusteater
09-19-2000, 03:28 PM
Valkyrie,... OK but what would be the name of the recordset? I built the Grid on the form not through code. Also, Here is what I am doing and maybe a FlexGrid would be better or at least someone would be able to help me with it. I have a table that has the following columns: Date (used for the day of the month, the user can't change this), TotSales (used for inputting in the total sales amount), ChrgTips (used for inputting a value), SalesTax(used to display the amount of sales tax..this is a calculated field, not one the user can edit), NetSales (used to display the net sales value...this is a calculated field, not one the user can edit). Would Flexgrid do the job I need? Also, how do you use the SendKeys Command?
Thanks a Million!!!!
Rick

Valkyrie
09-19-2000, 04:17 PM
Lets assume you DataControl name is Data1 (default name for first data control object.) The code would be:

<font color=blue>
Data1.Recordset.RecordCount
</font color=blue>

For the SendKeys command type SendKeys in a code module, put the cursor over it and press PF1. That will bring up the help file associated with that command. What event are you using to cause the cursor to move to the next row on Enter?



Quote of the moment....
"My job is so top secret even I don't know what I'm doing!"

dusteater
09-20-2000, 02:30 AM
Valkyrie... I am using a KeyUp event and if it is the Enter key then I use Row=Row+1

dusteater
09-20-2000, 12:32 PM
Valkyrie,
Well the recordset helped out a bunch!! I couldn't figure out how to change data in the grid directly but if I changed it in the recordset, it would update the grid and the SendKeys worked prefectly!! I am sure there must be another way to select the text but after hours of trying I gave up and this was a perfect fix! Also, when I used the DataGrid I did not use a DataControl, I used the properties of the grid to connect to a data environment so I tried to use that and it is great! You use DataEnvironment1.rsSales.RecordCount. Where DataEnvironment1 is the name of your Data Environment, rsSales is the name of the command in your data environment (make sure it matches the properties of your Data Grid), and the rest is obvious!
Thanks a million!!
Rick

Valkyrie
09-20-2000, 01:06 PM
Well dude...I'm glad that worked out OK for you. I've been horsing around with the DBGRID on your behalf and it works quite differently from the FlexGrid. The FlexGrid looks more professional in my opinion as the DBGrid looks too much like an Access view but the flexibility for add/mod/delete is there where as the FlexGrid is more of a display only grid. I've worked around that but it's not pretty to say the least. Sometimes you have to sacrifice form or function.

Anyways, good to know you were able to resolve it.

See ya on the boards....

Valkyrie! /images/icons/smile.gif

Quote of the moment....
"My job is so top secret even I don't know what I'm doing!"

dusteater
09-20-2000, 01:51 PM
Valkyrie,
Well that module is done...thanks to your help! I was messing around with Flexgrid but the code to input/change data was a bear... invisible text box....location to put text box in relationship to grid... I had two of the six columns that I needed to be edited and trying to get all this to work with flexgrid was more work. Then I realized that when you scrolled it messed up the whole thing....I figured I would stick with DataGrid, it is a little ugly but like you said you have to sacrafice something!!
Thanks again!!
Rick

Valkyrie
09-20-2000, 02:34 PM
Yup...that's what I did, plus I had to add extra hidden columns to hold my keys so that when someone does a sort I can keep track of the keys to use for updates. It's also slow as molasses but.....it looks gooooood!

Talk to you later.

Quote of the moment....
"My job is so top secret even I don't know what I'm doing!"

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum