DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 8 of 8

Thread: datagrid

  1. #1
    kei Guest

    datagrid


    I have some questions about datagrid control.

    1) Is it usual to allow user directly enter data on the datagrid?

    2) because datagrid can only operate in bound mode, so what the user typed
    is directly add to the underlying database, but the question is if the user
    does not want to save the change he made on the datagrid, what should he
    do?? (e.g. the user has deleted a record in the datagrid, and then want to
    discard this change later)

    3) Many application program has a function as follows:
    "When the user has changed some field but not saved yet and then want to
    quit the program, the application would tell the user that the change has
    not been saved yet", how can this fucntion be implemented in Visual Basic
    6? (Using Access 2000 as database)

    4) In fact, What is the selection criteria to use bound control or unbound
    control. (when to use one against another?)



  2. #2
    Arthur Wood Guest

    Re: datagrid


    Kei,

    I personally do not use bound controls, under ANY circumstances(that,
    however is a personal preference). I find that it is better to control what
    gets added to the database (and when) myself, in code. Bound controls make
    it very easy to develop an application, but they also make it very easy to
    get "contaminated" data into you tables. If the "business rules" which the
    data must satisfy to be considered "valid" are even the slightest bit beyond
    very basic, then you will have a great deal to trouble controlling the data
    when using bound controls.

    The answer to #2 is this: If by "later" you mean after some other record
    has been added, or modified, then NO the previously deleted record is totlaly
    gone, and cannot be recovered. If by later, you mean, that the user deletes
    the record and then, before moving to another record, decides to change is
    mind and "un-delete" the record, that can be accomplished usng the AfterDelete
    event which allows you to set a Cancel value to True, in order to Cancel
    the record deletion. However, if you do not cancel the delete, then once
    the record has been deleted, it is GONE.

    #3 again requires that you NOT use bound controls. With the bound control,
    once a record has been added, edited, or deleted, the database has been changed.
    There is no flag which indicates that "would tell the user that the change
    has not been saved yet", as that condition cannot exist with bound controls.
    By managing the data in your code, you can control when the records are
    updated. For data in a grid control, I always develop a "collection" class
    which manages all of the individual member records, and only updates all
    of the data back to the database when the user indicates that they want to
    save the data. This manager class can then keep track of the fact that the
    data has, or has not, been saved. If the user terminates the application
    before the manager class indicates that the data has been saved, then I can
    prompt the user that data has been changed but not saved, and allow them
    to decide to Save or NOT Save those changes.


    Arthur Wood


    "kei" <s946487@netvigator.com> wrote:
    >
    >I have some questions about datagrid control.
    >
    >1) Is it usual to allow user directly enter data on the datagrid?
    >
    >2) because datagrid can only operate in bound mode, so what the user typed
    >is directly add to the underlying database, but the question is if the user
    >does not want to save the change he made on the datagrid, what should he
    >do?? (e.g. the user has deleted a record in the datagrid, and then want

    to
    >discard this change later)
    >
    >3) Many application program has a function as follows:
    >"When the user has changed some field but not saved yet and then want to
    >quit the program, the application would tell the user that the change has
    >not been saved yet", how can this fucntion be implemented in Visual Basic
    >6? (Using Access 2000 as database)
    >
    >4) In fact, What is the selection criteria to use bound control or unbound
    >control. (when to use one against another?)
    >
    >



  3. #3
    kei Guest

    Re: datagrid


    "Arthur Wood" <wooda@saic-trsc.com> wrote:
    >
    >Kei,
    >
    > I personally do not use bound controls, under ANY circumstances(that,
    >however is a personal preference). I find that it is better to control

    what
    >gets added to the database (and when) myself, in code. Bound controls make
    >it very easy to develop an application, but they also make it very easy

    to
    >get "contaminated" data into you tables. If the "business rules" which

    the
    >data must satisfy to be considered "valid" are even the slightest bit beyond
    >very basic, then you will have a great deal to trouble controlling the data
    >when using bound controls.
    >
    >The answer to #2 is this: If by "later" you mean after some other record
    >has been added, or modified, then NO the previously deleted record is totlaly
    >gone, and cannot be recovered. If by later, you mean, that the user deletes
    >the record and then, before moving to another record, decides to change

    is
    >mind and "un-delete" the record, that can be accomplished usng the AfterDelete
    >event which allows you to set a Cancel value to True, in order to Cancel
    >the record deletion. However, if you do not cancel the delete, then once
    >the record has been deleted, it is GONE.
    >
    >#3 again requires that you NOT use bound controls. With the bound control,
    >once a record has been added, edited, or deleted, the database has been

    changed.
    > There is no flag which indicates that "would tell the user that the change
    >has not been saved yet", as that condition cannot exist with bound controls.
    > By managing the data in your code, you can control when the records are
    >updated. For data in a grid control, I always develop a "collection" class
    >which manages all of the individual member records, and only updates all
    >of the data back to the database when the user indicates that they want

    to
    >save the data. This manager class can then keep track of the fact that

    the
    >data has, or has not, been saved. If the user terminates the application
    >before the manager class indicates that the data has been saved, then I

    can
    >prompt the user that data has been changed but not saved, and allow them
    >to decide to Save or NOT Save those changes.
    >
    >
    >Arthur Wood
    >
    >
    >"kei" <s946487@netvigator.com> wrote:
    >>
    >>I have some questions about datagrid control.
    >>
    >>1) Is it usual to allow user directly enter data on the datagrid?
    >>
    >>2) because datagrid can only operate in bound mode, so what the user typed
    >>is directly add to the underlying database, but the question is if the

    user
    >>does not want to save the change he made on the datagrid, what should he
    >>do?? (e.g. the user has deleted a record in the datagrid, and then want

    >to
    >>discard this change later)
    >>
    >>3) Many application program has a function as follows:
    >>"When the user has changed some field but not saved yet and then want to
    >>quit the program, the application would tell the user that the change has
    >>not been saved yet", how can this fucntion be implemented in Visual Basic
    >>6? (Using Access 2000 as database)
    >>
    >>4) In fact, What is the selection criteria to use bound control or unbound
    >>control. (when to use one against another?)
    >>
    >>

    >

    Thanks for your kindly reply, arthur wood.

    1)I am very interested in the 'manager class' you mentioned in answer 3,
    could you give me more detail about how to implement this class (in fact,
    I am not very familiar with coding about class), also what grid control you
    use in answer 3?

    2) In VB6, is there any grid control that can operate in unbound mode? Also,
    is there any free grid control on internet for VB programmer to download?

    3) How do you compare delphi5 vs Visual Basic 6?

    kei


  4. #4
    Arthur Wood Guest

    Re: datagrid


    Kei,

    I would suggest that you should get a copy of
    "Visual Basic 6 Business Objects" by Rockford Lhotka, WORX Press, ISBN
    1-861001-07-X

    I use the MSFlexgrid and MSHFlexgrid controls which are provided with VB.
    Neither is required to be bound.

    I have done a little programming in Delphi, though not the most recent version.
    My problem with Delphi is that I have never used Pascal, nad so what little
    exposure I had was not very fruitful. I went through school before PCs (even
    before Mini-computers, yes it it was that long ago - more that 34 years since
    I graduated from College), and a) PAscal did not yet exiost, and b) even
    though Pascal is generally acknowledged to be a very powerful language, other
    than Delphi and a few high school (or possibly college) programming classes,
    NO ONE IN THE REAL WORLD uses Pascal, so there is almost no incentive to
    learn the language. I taught myself BASIC, ( along with a lot of other languages)
    because I had a real need to learn and use for the language at the time.
    From there, I progressed to VB (again self-taught, with the aid of $100s
    worth of books). I personally have no use for Delphi, and given the choice
    of where to put my effort in learning a new tool, would concentrate on VB
    long before even considering digging into Delphi.(If for no other reason
    than is provided by a quick glance at the Number of programming openings
    calling for experience in either VB (great big number), or Delphi(very small
    number))


    Arthur Wood


    "kei" <s946487@netvigator.com> wrote:
    >
    >"Arthur Wood" <wooda@saic-trsc.com> wrote:
    >>
    >>Kei,
    >>
    >> I personally do not use bound controls, under ANY circumstances(that,
    >>however is a personal preference). I find that it is better to control

    >what
    >>gets added to the database (and when) myself, in code. Bound controls

    make
    >>it very easy to develop an application, but they also make it very easy

    >to
    >>get "contaminated" data into you tables. If the "business rules" which

    >the
    >>data must satisfy to be considered "valid" are even the slightest bit beyond
    >>very basic, then you will have a great deal to trouble controlling the

    data
    >>when using bound controls.
    >>
    >>The answer to #2 is this: If by "later" you mean after some other record
    >>has been added, or modified, then NO the previously deleted record is totlaly
    >>gone, and cannot be recovered. If by later, you mean, that the user deletes
    >>the record and then, before moving to another record, decides to change

    >is
    >>mind and "un-delete" the record, that can be accomplished usng the AfterDelete
    >>event which allows you to set a Cancel value to True, in order to Cancel
    >>the record deletion. However, if you do not cancel the delete, then once
    >>the record has been deleted, it is GONE.
    >>
    >>#3 again requires that you NOT use bound controls. With the bound control,
    >>once a record has been added, edited, or deleted, the database has been

    >changed.
    >> There is no flag which indicates that "would tell the user that the change
    >>has not been saved yet", as that condition cannot exist with bound controls.
    >> By managing the data in your code, you can control when the records are
    >>updated. For data in a grid control, I always develop a "collection" class
    >>which manages all of the individual member records, and only updates all
    >>of the data back to the database when the user indicates that they want

    >to
    >>save the data. This manager class can then keep track of the fact that

    >the
    >>data has, or has not, been saved. If the user terminates the application
    >>before the manager class indicates that the data has been saved, then I

    >can
    >>prompt the user that data has been changed but not saved, and allow them
    >>to decide to Save or NOT Save those changes.
    >>
    >>
    >>Arthur Wood
    >>
    >>
    >>"kei" <s946487@netvigator.com> wrote:
    >>>
    >>>I have some questions about datagrid control.
    >>>
    >>>1) Is it usual to allow user directly enter data on the datagrid?
    >>>
    >>>2) because datagrid can only operate in bound mode, so what the user typed
    >>>is directly add to the underlying database, but the question is if the

    >user
    >>>does not want to save the change he made on the datagrid, what should

    he
    >>>do?? (e.g. the user has deleted a record in the datagrid, and then want

    >>to
    >>>discard this change later)
    >>>
    >>>3) Many application program has a function as follows:
    >>>"When the user has changed some field but not saved yet and then want

    to
    >>>quit the program, the application would tell the user that the change

    has
    >>>not been saved yet", how can this fucntion be implemented in Visual Basic
    >>>6? (Using Access 2000 as database)
    >>>
    >>>4) In fact, What is the selection criteria to use bound control or unbound
    >>>control. (when to use one against another?)
    >>>
    >>>

    >>

    >Thanks for your kindly reply, arthur wood.
    >
    >1)I am very interested in the 'manager class' you mentioned in answer 3,
    >could you give me more detail about how to implement this class (in fact,
    >I am not very familiar with coding about class), also what grid control

    you
    >use in answer 3?
    >
    >2) In VB6, is there any grid control that can operate in unbound mode? Also,
    >is there any free grid control on internet for VB programmer to download?
    >
    >3) How do you compare delphi5 vs Visual Basic 6?
    >
    >kei
    >



  5. #5
    vineet Guest

    Re: datagrid


    kei,

    I use datagrid in form with a ADODC support. What one can do is perhaps get
    your sql queries for datagrid as a recordset and then make a command button
    on the form .

    this command button would be a save button. when one has to save the data
    he will click this button . the codes for this button will cover the data
    grid itself and you have to update the recordset. use rs.update method. Use
    the following code



    Dim x As Integer
    Dim y As Integer

    x = -1
    Do While Not rs2.EOF
    x = x + 1
    For y = 0 To rs2.Fields.Count - 1
    DataGrid2.Col = y
    Debug.Print DataGrid1.Col
    DataGrid2.Row = x
    Debug.Print DataGrid2.Row
    Debug.Print DataGrid2.Text
    rs2.Update
    Next y
    rs2.MoveNext
    Loop

    here datagrid2 is your datagrid and rs2 is your recordset.
    loop through the whole datagrid and this will save .
    Before saving put a messagebox of confirmation of save.


    Hope this helps

    Vineet


  6. #6
    John K. Guest

    Re: datagrid


    First, I would agree with Arthur about Lhotka's book but if you've never done
    object-based programming, it's a tough read. I don't agree with all of his
    methodologies but...

    Anyway, Arthur, I'm also trying to use a grid-like control for unbound data
    entry but I don't think either of the 2 controls you've mentioned support
    direct editing unless you've found a way that I haven't. Can you elaborate
    on how you're using it?

    John.

    "Arthur Wood" <wooda@saic-trsc.com> wrote:
    >
    >Kei,
    >
    > I would suggest that you should get a copy of
    > "Visual Basic 6 Business Objects" by Rockford Lhotka, WORX Press, ISBN
    >1-861001-07-X
    >
    >I use the MSFlexgrid and MSHFlexgrid controls which are provided with VB.
    > Neither is required to be bound.



  7. #7
    Arthur Wood Guest

    Re: datagrid


    John,
    If, by non-bound grid you mean one in which you can edit directly within
    the grid itself, then I am not using these grids in that manner. I usually
    interpret "bound" control to mean one where the data is tied directly to
    the underlying data source through a data control. I use these grids to
    display my data, but I load the data via code, using a collection object
    to manage a collection of underlying data objects. When the user wants to
    edit an entry in the grid, they select the entry, which is then used to choose
    the corresponding member of the collection, which is used to populate individual
    text boxes, combo-boxes (or whatever is called for to show the data for that
    entry) where the edits can be made and validated, before refreshing the grid
    (nothing yet saved back to the database). Only when the user is satisfied
    with all of their changes, do I then save all of the editted records back
    to the database. This is in keeping with Lhotka's approach, and allows the
    user the flexibilty to "undo" any changes, up to the point when they are
    finally comitted to the database.

    Arthur Wood
    "John K." <johnchulkang@hotmail.com> wrote:
    >
    >First, I would agree with Arthur about Lhotka's book but if you've never

    done
    >object-based programming, it's a tough read. I don't agree with all of

    his
    >methodologies but...
    >
    >Anyway, Arthur, I'm also trying to use a grid-like control for unbound data
    >entry but I don't think either of the 2 controls you've mentioned support
    >direct editing unless you've found a way that I haven't. Can you elaborate
    >on how you're using it?
    >
    >John.
    >
    >"Arthur Wood" <wooda@saic-trsc.com> wrote:
    >>
    >>Kei,
    >>
    >> I would suggest that you should get a copy of
    >> "Visual Basic 6 Business Objects" by Rockford Lhotka, WORX Press, ISBN
    >>1-861001-07-X
    >>
    >>I use the MSFlexgrid and MSHFlexgrid controls which are provided with VB.
    >> Neither is required to be bound.

    >



  8. #8
    kei Guest

    Re: datagrid


    I still have some problems about the unbound grid control.

    Q1)After adding, deleting and updating some records in the unbound grid control,
    how can we save back the modified records to the underlying database?
    Is it necessary to remember which records have been newly added, deleted
    and updated respectively since the last saved action and then modified ONLY
    THESE records in the underlying table? But how can these be implemented?

    Q2)is it foolish to delete all records in the underlying table and then save
    all records in the grids to the underlying table by looping through all rows
    and columns of the grid.

    Thank You!!

    Kei



    "Arthur Wood" <wooda@saic-trsc.com> wrote:
    >
    >John,
    > If, by non-bound grid you mean one in which you can edit directly within
    >the grid itself, then I am not using these grids in that manner. I usually
    >interpret "bound" control to mean one where the data is tied directly to
    >the underlying data source through a data control. I use these grids to
    >display my data, but I load the data via code, using a collection object
    >to manage a collection of underlying data objects. When the user wants

    to
    >edit an entry in the grid, they select the entry, which is then used to

    choose
    >the corresponding member of the collection, which is used to populate individual
    >text boxes, combo-boxes (or whatever is called for to show the data for

    that
    >entry) where the edits can be made and validated, before refreshing the

    grid
    >(nothing yet saved back to the database). Only when the user is satisfied
    >with all of their changes, do I then save all of the editted records back
    >to the database. This is in keeping with Lhotka's approach, and allows

    the
    >user the flexibilty to "undo" any changes, up to the point when they are
    >finally comitted to the database.
    >
    >Arthur Wood



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center