Answered by:
DatagridViewColumn.ReadOnly throws System.ArgumentOutOfRangeException

Question
-
Hy!
I have a data-bounded datagridview. When i try to set the datagridviewcolumn readonly property to false or true i get the following exception:
A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll Additional information: Az index az engedélyezett tartományon kívül esett. Az index nem lehet negatív, és kisebbnek kell lennie a gyűjtemény méreténél. If there is a handler for this exception, the program may be safely continued.
This exceptions throws only, if all cell's values is 0 in the specified column. When one cell value is not 0, then the exception will not thrown.
I have no idea what is this... maybe a bug?
Thanks for help!
Greets,
SZL
SZL
- Moved by Carl Cai Tuesday, February 11, 2014 1:54 AM (from vb.net) issues related to third-party are not supported
Friday, February 7, 2014 8:42 PM
Answers
-
I forgot to say one important thing: this is not the original DataGridView control, this is a third party component DotNetBar's DataGridViewX control, with DataGridViewDoubleInput column (but these controls inherits from the original controls and the ReadOnly property was not rewritten).
Success
CorMonday, February 10, 2014 8:37 AM
All replies
-
Hi,
Welcome to MSDN.
I created a simple sample to test with the following code:
Public Class Form1 Dim dt As New DataTable Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load With dt With .Columns .Add("col1") .Add("col2") .Add("col3") End With With .Rows .Add({0, 2, 0}) .Add({0, 0, 0}) .Add({1, 0, 0}) .Add({0, 0, 0}) .Add({0, 0, 0}) End With End With DataGridView1.DataSource = dt End Sub Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click Try For Each c As DataGridViewColumn In DataGridView1.Columns c.ReadOnly = Not c.ReadOnly Next MsgBox("done") Catch ex As Exception MsgBox(ex.ToString()) End Try End Sub End Class
I could not reproduce this issue in my side, in order to make this issue clear, you could share more information with us.
If you add a line as following code, what will it show?
For Each c As DataGridViewColumn In DataGridView1.Columns MsgBox(c.Index & "+" & c.Name) c.ReadOnly = Not c.ReadOnly Next
You could create a simple sample which has the same issue and share it with us by uploading it to skydrive and sharing the link with us.
Regards.
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.Monday, February 10, 2014 2:52 AM -
Hi,
Thanks for reply. I try to reproduce the issue in a new project, but in new project the exception not thrown.
I forgot to say one important thing: this is not the original DataGridView control, this is a third party component DotNetBar's DataGridViewX control, with DataGridViewDoubleInput column (but these controls inherits from the original controls and the ReadOnly property was not rewritten).
I thinking that the issue thrown with original control, because it is similar with this post: ArgumentOutOfRangeException (possible that I'm wrong).
The messagebox line in your example executed well, it writes the index and name to messagebox with all column. (When only the Readonly part is in Try...Catch)
Unfortunately I cannot upload the entire project, because it is very huge with more dll-s and db connection, but i found a workaround to solve the problem (without Try..Catch :) )
I need to place this code before For, and the exception not thown anymore:
dgvList.ReadOnly = False dgvList.ReadOnly = True
One problem, that the columns readonly property will not set great in this case, so i need to use Try..Catch, therefore not affect the program logic.
SZL
Monday, February 10, 2014 8:06 AM -
Hi,
Glad to receive your reply.
But I am afraid that issues related to third-party are not supported in these forums.
I would suggest you consider posting this issue in the website of the publisher of that control.
In addition, if you change that control to original, will it has the same issue?
If so, you could share that sample with us, I will test it in my side.
Thanks for your understanding.
Regards.
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.Monday, February 10, 2014 8:35 AM -
I forgot to say one important thing: this is not the original DataGridView control, this is a third party component DotNetBar's DataGridViewX control, with DataGridViewDoubleInput column (but these controls inherits from the original controls and the ReadOnly property was not rewritten).
Success
CorMonday, February 10, 2014 8:37 AM -
Hi!
Oh sorry, i am new here. :)
I try to change the component to original, but the control and the columns are referenced many place in my code and i cannot change it easily.
When i can make a sample with the issue i will upload it to skydrive and share it here. I will contact also with the authors.Thanks for help!
SZL
Monday, February 10, 2014 9:53 AM -
I try to change the component to original, but the control and the columns are referenced many place in my code and i cannot change it easily.Hi,
I have moved this thread here since this issue is related to third-party.
If you still have the same issue with original DataGridView control, you could post a new thread in vb.net forum.
We will focus on that new thread to help you.
Thanks for your understanding.
Regards.
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.Tuesday, February 11, 2014 1:57 AM -
Hi,
Ok, thank you!
SZL
Tuesday, February 11, 2014 7:48 AM