CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 3 123 LastLast
Results 1 to 15 of 34
  1. #1
    Join Date
    Jul 1999
    Location
    Athens, Hellas
    Posts
    769

    Grid or Text Boxes ?

    I want to create a table where the user can insert some values (nothing to do with database). Which is the better way to use: DBGrid (unbound mode) or many text boxes near to each other as a control array?

    Michael Vlastos
    Automation Engineer
    Company Modus SA
    Development Department
    Athens, Greece

  2. #2
    Join Date
    May 1999
    Posts
    3,332

    Re: Grid or Text Boxes ?

    I'd use a DBGrid.
    Why?
    with textboxes you'd probably have to implement scrolling(keyboard AND mouse) very soon.

    Even if your app has nothing to do with a database I'd still use bound mode and use a disconnected recordset (as I have been trying to advertise for many many months in this forum :-)).


  3. #3
    Join Date
    Jul 1999
    Location
    Athens, Hellas
    Posts
    769

    How to?

    Ok I'll try use your way. Can you tell me how to?
    (although you may told me again but I don't remember...).
    Have in mind that I want to satisfy these:
    1. The user can delete any row, by selecting and pressing delete.
    2. The user can add a row at the end.
    3. The values that inserts on grid must be under some rules (I will build a knowledge based system-grid with many rules, checking and control)
    Having all these in mind could you post the right code for it?
    (The size of the grid will be at about 18 columns and 500 rows...)
    Thank you Lothar!

    Michael Vlastos
    Automation Engineer
    Company Modus SA
    Development Department
    Athens, Greece

  4. #4
    Join Date
    May 1999
    Posts
    3,332

    Re: How to?

    Unfortunately, I do not have the time to write your application :-)
    requirements 1 and 2 are properties of the dbgrid. It's easy to set allowAddnew and allowdelete to true.

    to implement validation logic you can do this in your save logic (probably triggered from a button or menu).

    here is a small sample to use a dbgrid in bound mode without a database.


    Dim r as ADOR.Recordset
    set r = new ADOR.Recordset

    r.Fields.Append "firstfield", adInteger
    r.Fields.Append "secondfield", adInteger
    r.CursorType = adOpenDynamic
    r.Open
    r.AddNew
    r.Fields(0).Value = 1
    r.Fields(1).Value = 2
    r.AddNew
    r.Fields(0).Value = 3
    r.Fields(1).Value = 4
    set g.DataSource = r



    by setting AllowAddNew and AllowDelete to True, I was able to add new rows and delete selected rows.

    This has been tested unter
    NT4 SP 5
    VB 6 SP3

    Good luck.



  5. #5
    Join Date
    May 1999
    Posts
    3,332

    Re: How to?

    One more point. I didn't even have to add the complete ADO reference, but only the small ADOR recordset library!


  6. #6
    Join Date
    Jul 1999
    Location
    Athens, Hellas
    Posts
    769

    Some corrections...

    The right code sould be this:

    Dim r as ADOR.Recordset
    set r = new ADOR.Recordset
    r.Fields.Append "firstfield", adInteger
    r.Fields.Append "secondfield", adInteger
    r.CursorType = adOpenDynamic
    r.Open
    r.AddNew
    r.Fields(0).Value = 1
    r.Fields(1).Value = 2
    r.AddNew
    r.Fields(0).Value = 3
    r.Fields(1).Value = 4
    set g = r.DataSource



    Right? But what is g?
    How to define it?
    Thanx Lothar!!!

    Michael Vlastos
    Automation Engineer
    Company Modus SA
    Development Department
    Athens, Greece

  7. #7
    Join Date
    May 1999
    Posts
    3,332

    Re: Some corrections...

    I don't see what makes you code "righter" than mine, since mine worked.
    Anyway, "g" is the name of my dbgrid object on the form. I'm lazy, that's why all my controls have short names :-)


  8. #8
    Join Date
    Jul 1999
    Location
    Athens, Hellas
    Posts
    769

    Re: Some corrections...

    Only the last line of your code was inversed!
    And this is not my code... All is yours!!!
    So, thank you a lot.
    Rating comes soon...

    Michael Vlastos
    Automation Engineer
    Company Modus SA
    Development Department
    Athens, Greece

  9. #9
    Join Date
    Jul 1999
    Location
    Athens, Hellas
    Posts
    769

    Is that right?


    set DBGrid1 = r.DataSource



    Are you sure? This doesn't work...

    Michael Vlastos
    Automation Engineer
    Company Modus SA
    Development Department
    Athens, Greece

  10. #10
    Join Date
    May 1999
    Posts
    3,332

    Re: Is that right?

    I'm confused. I guess you are right.


  11. #11
    Join Date
    Jul 1999
    Location
    Athens, Hellas
    Posts
    769

    OK I am right but how is the right code?

    Please can you post me the right code, because I am very curious to explore your way...
    It seems very simple to be true!!!
    :-)

    Michael Vlastos
    Automation Engineer
    Company Modus SA
    Development Department
    Athens, Greece

  12. #12
    Join Date
    May 1999
    Posts
    3,332

    Re: OK I am right but how is the right code?

    Set YourGridNameGoesHere.DataSource = r
    should do it.


  13. #13
    Join Date
    Jul 1999
    Location
    Athens, Hellas
    Posts
    769

    Still doesn't work...

    It displays the following message:
    "Class doesn't support Automation or does not support expected interface"
    ??? :-o

    Michael Vlastos
    Automation Engineer
    Company Modus SA
    Development Department
    Athens, Greece

  14. #14
    Join Date
    May 1999
    Posts
    3,332

    Re: Still doesn't work...

    Looks like we are using different grids?!
    I have already thrown away my sample project. Try using one of the grids that supports ADO data binding.


  15. #15
    Join Date
    Jul 1999
    Location
    Athens, Hellas
    Posts
    769

    Still doesn't work...

    I use:
    Microsoft Data Bound Grid Control 5 (SP3). Is that the same with yours?
    Yes, it has datasource property!

    Michael Vlastos
    Automation Engineer
    Company Modus SA
    Development Department
    Athens, Greece

Page 1 of 3 123 LastLast

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

Featured