Results 1 to 5 of 5

Thread: Adding new records in Dbgrid

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jul 1999
    Location
    Saudi Arabia, Gulf side, Qatif
    Posts
    142
    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

  2. #2
    Lively Member
    Join Date
    Aug 2000
    Location
    Holden Beach NC
    Posts
    85
    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.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jul 1999
    Location
    Saudi Arabia, Gulf side, Qatif
    Posts
    142
    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

  4. #4
    Lively Member
    Join Date
    Aug 2000
    Location
    Holden Beach NC
    Posts
    85
    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

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Jul 1999
    Location
    Saudi Arabia, Gulf side, Qatif
    Posts
    142
    Good Idea,,,,,,,,,Thanks

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