Results 1 to 15 of 15

Thread: MSHFlex Grid

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2001
    Posts
    1,384

    MSHFlex Grid

    Does anyone have sample code for using the MSHFlex Grid? That, for adding/editing/saving and deleting data in it. I am connecting to MS Access via adodc.
    Mel

  2. #2
    khalik
    Guest
    AFAIK i have poster several times for flexgrid.......
    it is better to search

    i asure u u will find a lot...

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2001
    Posts
    1,384
    I have looked but can't find what I need. I know how to save an edited grid to a database.
    Code:
    Private Sub cmdSave_Click()
    
    RS.MoveFirst
    
    For R = 1 To MSHFlexGrid1.Rows - 1
      
      RS.Fields("Name") = MSHFlexGrid1.TextMatrix(R, 0)
      RS.Fields("Address") = MSHFlexGrid1.TextMatrix(R, 1)
      'etc ....
      RS.MoveNext
    Next
    
    End Sub
    To add new data to the database
    Code:
    Private Sub cmdSave_Click()
    
      For R = 1 To MSHFlexGrid1.Rows - 1
        With RS
            .AddNew
            .Fields("Name") = MSHFlexGrid1.TextMatrix(R, 0)
            .Fields("Address") = MSHFlexGrid1.TextMatrix(R, 1)
            'etc ....
            .Update
        End With
      Next
    
    End Sub
    But when I try to amalgamate both, i.e. to allow the user to both add new data, edit existing data I run into problems.

    Does anyone have better coding for this?
    Mel

  4. #4
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    How are you distinguishing between saving and adding new?
    How are you adding data to the flexgrid?

    I'm using a borderless textbox, and in the textbox lostfocus event, I update the database.

    How do you want to do it?

  5. #5
    khalik
    Guest
    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Form_Load()
    4. Text1.Visible = False
    5. End Sub
    6.  
    7. Private Sub MSF_EnterCell()
    8. With Text1
    9.     .Left = msf.CellLeft
    10.     .Top = msf.CellTop
    11.     .Height = msf.CellHeight
    12.     .Width = msf.CellWidth
    13.     .Text = msf.Text
    14.     .Visible = True
    15.     .SetFocus
    16. End With
    17. End Sub
    18.  
    19. Private Sub msf_LeaveCell()
    20. msf.Text = Text1
    21. Text1.Visible = False
    22. End Sub

    grid

  6. #6

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2001
    Posts
    1,384
    I am using borderless text boxs to edit my grid. And have similar code. The problem arises when I add/Edit data in the grid. How do you go about doning this? To you have two separate events for i) adding new data and saving AND ii) editing existing data and saving? And how do you handle the situation when the user edit existing data but also adds new lines to the grid?
    Mel

  7. #7
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    Originally posted by mel_flynn

    How do you go about doning this? To you have two separate events for

    i) adding new data and saving AND


    ii) editing existing data and saving? And how do you handle the situation when the user edit existing data but also adds new lines to the grid?
    In your flexgrid, you'll obviously have a primary key column (ok, assume). So, whenever you're to fire the event, check the cell for the existence of any content in the cell, and based upon that, set a boolean variable. Based upon the boolean var being true or false you can either addnew or update. (I use the objconn.execute method). This should cover both editing existing data and adding new data.

  8. #8
    khalik
    Guest
    insert or update code will be the same to flexgrid
    only when u write data to database

    loop to no of rows in grid
    open the recordset with the unique key ..
    if found then old record
    update the values
    if not found new record
    use addnew method

  9. #9

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2001
    Posts
    1,384
    No element in my grid is unique. The grid is acting as a details section
    VB Code:
    1. With adoQuoteDets
    2.             .ConnectionString = dataBase
    3.             .RecordSource = "Select * From QuoteDets WHERE QuoteNo = " & cboQuoteNo.Text
    4.             .CursorLocation = adUseClient
    5.         End With
    6.  
    7.         Set grd.DataSource = adoQuoteDets
    So there could be a series of lines for the one quote number.

    Has anyone a sample application that they use MSHFlex Grid, incl. Adding, editing, deleting data in the grid? Any samples I have either only allowa the user to edit existing data or to only add new data.
    Mel

  10. #10
    khalik
    Guest
    then what i can suggest
    use transaction

    delete the rows and make new entry into it...

    hope u dont have any child to u table

  11. #11

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2001
    Posts
    1,384
    delete the rows and make new entry into it...
    This is what I was thinking of doing, but how do I only delete the data in the recordser without removing the contents of the grid?
    Mel

  12. #12
    khalik
    Guest
    Originally posted by mel_flynn
    This is what I was thinking of doing, but how do I only delete the data in the recordser without removing the contents of the grid?
    do u keep track of the record status in the flexgrid...

    AFAIK the best thing what u can do is

    delete the rows from the tabel...
    Code:
    QuoteDets WHERE QuoteNo = " & cboQuoteNo.Text
    and loop around and make insert

    nothign to do with u grid contents clearing if u clear the grid u will lose what u have.... nothing to insert in database

  13. #13

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2001
    Posts
    1,384
    delete the rows from the table...
    QuoteDets WHERE QuoteNo = " & cboQuoteNo.Text
    How do I delete rows from a table using the SQL statement?
    Mel

  14. #14

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2001
    Posts
    1,384
    How do I delete specific data from a table using the SQL statement?
    i.e. Delete * From QuoteDets WHERE QuoteNo = " & cboQuoteNo.Text
    Mel

  15. #15
    khalik
    Guest
    Originally posted by mel_flynn
    How do I delete specific data from a table using the SQL statement?
    i.e. Delete * From QuoteDets WHERE QuoteNo = " & cboQuoteNo.Text
    u r question has the answer... the query which u pasted does that...

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