|
-
Oct 8th, 2000, 08:38 AM
#1
Thread Starter
Addicted Member
How can I make the cell of a dbgrid active and ready for the input by a user when addnew record button is clicked, when addnew activated new row will be added but the cursor will not be ready unless user click on this cell, I tried setfocus but it did not work, Any idea will be appriciated
Thanks
-
Oct 8th, 2000, 10:27 AM
#2
Lively Member
Originally posted by maqmaq
How can I make the cell of a dbgrid active and ready for the input by a user when addnew record button is clicked, when addnew activated new row will be added but the cursor will not be ready unless user click on this cell, I tried setfocus but it did not work, Any idea will be appriciated
Thanks
First: why not just set the properties in the dbGrid so that Allow Add New = TRUE? But if you want an "ADD NEW" button then highlighting the new record depends somewhat on how you add the new record. If you are using an SQL INSERT command and you have an auto-number key field and the new record will be included in your Data object's recrodset as the last record then: after the SQL statement is executed refresh your data object then use DATA1.Recordset.MoveLast method. If you are using Data1.AddNew, then set default values(if you do not have default values set in the Table Properties of the Database) and use Data1.Update. Then use Data1.Recordset.MoveLast. Remember that the dbGrid control is a reflection of the Data Control. What I would suggest is creating a frame with controls corresponding to the fields that you want the user to enter and making the frame visible in the click event of the "ADD NEW" command button. Force navigation through the fields by trapping for arrows and <ENTER> keys. Add command buttons to the frame that "ADD NOW" "CANCEL" and "ADD NOW ENTER ANOTHER"....The advantage here is that you can add code to validate the data before it enters the database. You can, of course, enter this same error checking into the Data control's corresponding events. Or a best answer solution would be to encapsulate the error checking into a module or class and have the events that might trigger an error check all of the data in question. The advantage to a dbGrid is that it is a very quick and easy way to display, edit and add data. The downside is that it is very hard to wrestle control from. Depending on the scale of your app, most of the time if you want control you need to take control through simple objects and preclude all possible user mistakes. Use of interfaces with error checking help keep data the way it needs to be.
-
Oct 8th, 2000, 01:44 PM
#3
Thread Starter
Addicted Member
Thanks for your reply
I agree with you that using Dbgrid for data input is little bit hard, I will use it as a data desplay, I will create a seperate form for data input so it will be easy for mew to control the user input.
Thanks a gain
maqmaq
-
Oct 9th, 2000, 06:55 AM
#4
Lively Member
Originally posted by maqmaq
Thanks for your reply
I agree with you that using Dbgrid for data input is little bit hard, I will use it as a data desplay, I will create a seperate form for data input so it will be easy for mew to control the user input.
Thanks a gain
maqmaq
Use a frame instead of a form. Simply change the frame1.visible property to TRUE when you want the user to enter data, and to FALSE when the user is done. This will keep all of the code for this portion of your app local to that form.
Hunter
-
Oct 9th, 2000, 08:14 AM
#5
Thread Starter
Addicted Member
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|