CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: MS Flex Grid

  1. #1
    Join Date
    Feb 2010
    Posts
    21

    MS Flex Grid

    hey, i am using the following code to save values from a flex grid to access db

    tblHrData("UniOrEq") = MSFlexGrid1.TextMatrix(currow1, 1)
    tblHrData("Degs") = MSFlexGrid1.TextMatrix(currow1, 2)
    tblHrData("Dips") = MSFlexGrid1.TextMatrix(currow1, 3)

    but this code only saves one row if i modify it to the code below it saves the headers instead, in option explicit i have declared currow1 & 2 as variants

    Dim confirm, n, dbrow As Integer
    dbrow = MSFlexGrid1.RowSel
    k = "abc"
    currow1 = MSFlexGrid1.RowSel

    tblHrData("UniOrEq2") = MSFlexGrid1.TextMatrix(currow2, 1)
    tblHrData("Degs2") = MSFlexGrid1.TextMatrix(currow2, 2)
    tblHrData("Dips2") = MSFlexGrid1.TextMatrix(currow2, 3)

    k = MSFlexGrid1.TextMatrix(currow1, 0)
    For n = 0 To 6
    MSFlexGrid1.TextMatrix(currow1, n) = ""
    MSFlexGrid1.TextMatrix(currow2, n) = ""

    Next n

    any ideas on how to overcome this? Pleeeeeeeeeeease

    Thanks

  2. #2
    Join Date
    Jul 2006
    Location
    Germany
    Posts
    3,725

    Re: MS Flex Grid

    Maybe for n=1 to 6 helps?

    in option explicit i have declared currow1 & 2 as variants
    What is the meaning of this?

  3. #3
    Join Date
    Dec 2009
    Posts
    596

    Re: MS Flex Grid

    I see that you intialized you initialized variable "currow1" with currow1 = MSFlexGrid1.RowSel. What value is in "currow2"?

    And with this following snippit
    "tblHrData("UniOrEq2") = MSFlexGrid1.TextMatrix(currow2, 1)
    tblHrData("Degs2") = MSFlexGrid1.TextMatrix(currow2, 2)
    tblHrData("Dips2") = MSFlexGrid1.TextMatrix(currow2, 3)

    it appears you're trying to deal with three columns per row but the way you are handling it with

    For n = 0 To 6
    MSFlexGrid1.TextMatrix(currow1, n) = ""
    MSFlexGrid1.TextMatrix(currow2, n) = "" The code is going to look for seven columns per row; for currow1 and currow2(which isn't intialized from what i can tell and for what it's worth)

    Do (for n = 0 to 2) Per row

    Hope that helps.

  4. #4
    Join Date
    Feb 2008
    Location
    Bangalore
    Posts
    149

    Re: MS Flex Grid

    Quote Originally Posted by RussKass View Post
    hey, i am using the following code to save values from a flex grid to access db

    tblHrData("UniOrEq") = MSFlexGrid1.TextMatrix(currow1, 1)
    tblHrData("Degs") = MSFlexGrid1.TextMatrix(currow1, 2)
    tblHrData("Dips") = MSFlexGrid1.TextMatrix(currow1, 3)

    but this code only saves one row if i modify it to the code below it saves the headers instead, in option explicit i have declared currow1 & 2 as variants
    Code:
        Dim confirm, n, dbrow As Integer
        dbrow = MSFlexGrid1.RowSel
        k = "abc"
        currow1 = MSFlexGrid1.RowSel '<----- here you are assiging value to currow1
    
        tblHrData("UniOrEq2") = MSFlexGrid1.TextMatrix(currow2, 1) '<-- here you are using Currow2  for which value is not assigned
        tblHrData("Degs2") = MSFlexGrid1.TextMatrix(currow2, 2)'<-- here you are using Currow2 for which value is not assigned
        tblHrData("Dips2") = MSFlexGrid1.TextMatrix(currow2, 3)'<-- here you are using Currow2 for which value is not assigned
    
        k = MSFlexGrid1.TextMatrix(currow1, 0)
        For n = 0 To 6
            MSFlexGrid1.TextMatrix(currow1, n) = ""
            MSFlexGrid1.TextMatrix(currow2, n) = ""
    
        Next n
    I can see you are assigning value to Currow1 Not to Currow2, but you are using currow2 to access the value from MSFlexGrid1.

    My guess is that, you have declared Currow2 variant variable but not initialised/assigned any value,
    so it is taking value 0. So 0th row is nothing but column header!!
    Last edited by ComITSolutions; February 27th, 2010 at 01:38 AM.
    Encourage the efforts of fellow members by rating

    Lets not Spoon Feed and create pool of lazy programmers

    - ComIT Solutions

  5. #5
    Join Date
    Feb 2010
    Posts
    21

    Re: MS Flex Grid

    Hey,

    4got to mention this is only an extract i am actually having 7 colums in this grid how would i assign a value to currow2,3,4,5,6 etc to enable data in those rows to be saved?
    Last edited by RussKass; March 3rd, 2010 at 08:34 AM.

  6. #6
    Join Date
    Feb 2008
    Location
    Bangalore
    Posts
    149

    Re: MS Flex Grid

    In that case you can use loop to save data row by row.

    Code:
    For RowNo = 1 to MSFlexGrid1.rows-1
       '... Saving code  (note: Use RowNo variable instead of currow1,currow2 ...
    
    Next RowNo
    Encourage the efforts of fellow members by rating

    Lets not Spoon Feed and create pool of lazy programmers

    - ComIT Solutions

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