gixxerrider73
New member
- Joined
- Nov 18, 2012
- Messages
- 4
- Programming Experience
- Beginner
I have a windows for with a Datagridview. I use the code below with check boxes to show/hide the columns. There are 14 columns and it works fine except for columns index 0, 1, 3. the code is exactly the same for all of the columns. Any thoughts?
This is the code the that throws the error
Private
Sub SysCheckbox_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SysCheckbox.CheckedChanged
If SysCheckbox.Checked Then
DataGridView1.Columns(0).Visible = true
Else
DataGridView1.Columns(0).Visible = false
End If
End Sub
This is the error
System.InvalidOperationException was unhandled
Message="An error occurred creating the form. See Exception.InnerException for details. The error is: Index was out of range. Must be non-negative and less than the size of the collection.\r\nParameter name: index"
Source="HyperMedia"
StackTrace:
at HyperMedia.My.MyProject.MyForms.Create__Instance__[T](T Instance) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 190
at HyperMedia.My.MyProject.MyForms.get_Tab()
at HyperMedia.My.MyApplication.OnCreateMainForm() in D:\Jay_Data\Arcade\Software Develope\HyperMedia\HyperMedia\My Project\Application.Designer.vb:line 35
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
at HyperMedia.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
at System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext, String[] activationCustomData)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssemblyDebugInZone()
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException: System.ArgumentOutOfRangeException
Message="Index was out of range. Must be non-negative and less than the size of the collection.\r\nParameter name: index"
Source="mscorlib"
ParamName="index"
StackTrace:
at System.Collections.ArrayList.get_Item(Int32 index)
at System.Windows.Forms.DataGridViewColumnCollection.get_Item(Int32 index)
at HyperMedia.Tab.SysCheckbox_CheckedChanged(Object sender, EventArgs e) in D:\Software Develope\HyperMedia\HyperMedia\Tab.vb:line 625
at System.Windows.Forms.CheckBox.OnCheckedChanged(EventArgs e)
at System.Windows.Forms.CheckBox.set_CheckState(CheckState value)
at HyperMedia.Tab.InitializeComponent() in D:\Software Develope\HyperMedia\HyperMedia\Tab.Designer.vb:line 503
at HyperMedia.Tab..ctor()
InnerException:
This is the code the that throws the error
Private
Sub SysCheckbox_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SysCheckbox.CheckedChanged
If SysCheckbox.Checked Then
DataGridView1.Columns(0).Visible = true
Else
DataGridView1.Columns(0).Visible = false
End If
End Sub
This is the error
System.InvalidOperationException was unhandled
Message="An error occurred creating the form. See Exception.InnerException for details. The error is: Index was out of range. Must be non-negative and less than the size of the collection.\r\nParameter name: index"
Source="HyperMedia"
StackTrace:
at HyperMedia.My.MyProject.MyForms.Create__Instance__[T](T Instance) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 190
at HyperMedia.My.MyProject.MyForms.get_Tab()
at HyperMedia.My.MyApplication.OnCreateMainForm() in D:\Jay_Data\Arcade\Software Develope\HyperMedia\HyperMedia\My Project\Application.Designer.vb:line 35
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
at HyperMedia.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
at System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext, String[] activationCustomData)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssemblyDebugInZone()
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException: System.ArgumentOutOfRangeException
Message="Index was out of range. Must be non-negative and less than the size of the collection.\r\nParameter name: index"
Source="mscorlib"
ParamName="index"
StackTrace:
at System.Collections.ArrayList.get_Item(Int32 index)
at System.Windows.Forms.DataGridViewColumnCollection.get_Item(Int32 index)
at HyperMedia.Tab.SysCheckbox_CheckedChanged(Object sender, EventArgs e) in D:\Software Develope\HyperMedia\HyperMedia\Tab.vb:line 625
at System.Windows.Forms.CheckBox.OnCheckedChanged(EventArgs e)
at System.Windows.Forms.CheckBox.set_CheckState(CheckState value)
at HyperMedia.Tab.InitializeComponent() in D:\Software Develope\HyperMedia\HyperMedia\Tab.Designer.vb:line 503
at HyperMedia.Tab..ctor()
InnerException: