-
Apr 26th, 2015, 12:39 AM
#1
Thread Starter
Frenzied Member
[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 !
-
Apr 26th, 2015, 01:05 AM
#2
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
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Apr 26th, 2015, 01:29 AM
#3
Thread Starter
Frenzied Member
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.
-
Apr 26th, 2015, 01:33 AM
#4
Re: What is problem with this code ?
do you have at least 11 columns in your dgv?
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Apr 26th, 2015, 01:45 AM
#5
Thread Starter
Frenzied Member
Re: What is problem with this code ?
-
Apr 26th, 2015, 01:50 AM
#6
Re: What is problem with this code ?
in DataGridView1 on Form1?
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Apr 26th, 2015, 02:00 AM
#7
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?
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Apr 26th, 2015, 03:45 AM
#8
Thread Starter
Frenzied Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|