Results 1 to 8 of 8

Thread: [RESOLVED] What is problem with this code ?

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2010
    Posts
    1,462

    Resolved [RESOLVED] What is problem with this code ?

    Code:
        Dim xc, i
            With Form1.DataGridView1
                For i = 3 To 10
                    xc = .Columns(i).Width
                    Debug.Print(xc)
                Next
    
            End With
    Thanks, I have it in a module and I'm sure it worked yesterday !

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,467

    Re: What is problem with this code ?

    works fine for me after explicitly declaring variables. don't forget Debug.Print works with strings...

    Code:
    Module Module1
        Public Sub doLoop()
            Dim xc, i As Integer
            With Form1.DataGridView1
                For i = 3 To 10
                    xc = .Columns(i).Width
                    Debug.Print(xc.ToString)
                Next
            End With
        End Sub
    End Module

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2010
    Posts
    1,462

    Re: What is problem with this code ?

    Thanks Paul, but this giving me the same error on Line xc =

    There's a red underline on the h in .Width

    ArgumentOutOfRangeException was unhandled

    Index was out of range. Must be non-negative and less than the size of the collection.
    Parameter name: index

    Tips

    Make sure the arguments to this method have valid values.
    If you are working with a collection, make sure the index is less than the size of the collection.
    When using the overloaded two-argument FindString or FindExactString methods with a ComboBox or ListBox, check the startIndex parameter.
    Get general help for this exception.

  4. #4
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,467

    Re: What is problem with this code ?

    do you have at least 11 columns in your dgv?

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2010
    Posts
    1,462

    Re: What is problem with this code ?

    Yes, I've got 96 !

  6. #6
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,467

    Re: What is problem with this code ?

    in DataGridView1 on Form1?

  7. #7
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,467

    Re: What is problem with this code ?

    are the columns added dynamically at run time? is there a chance you're running the code when you have less than 11 columns?

  8. #8

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2010
    Posts
    1,462

    Re: What is problem with this code ?

    Ah, yes Paul. Sanity restored. The grid itself wasn't even established.
    All going shell now

    Thank you.

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