Exception 在mono中分配datagridview的数据源时ArgumentOutOfRange异常

Exception 在mono中分配datagridview的数据源时ArgumentOutOfRange异常,exception,datagridview,mono,Exception,Datagridview,Mono,在datagridview中分配数据源时ArgumentOutOfRange异常 编辑: 当我使用List代替BindingList时,这段代码运行良好 环境: 单声道4.0.12。C#winform应用程序 代码: public class DataGridViewStudyReference : CustomControls.DataGridViewDataEntry<StudyRefrenceValueBusinessObjectNew> { } public class

在datagridview中分配数据源时ArgumentOutOfRange异常

编辑: 当我使用List代替BindingList时,这段代码运行良好

环境: 单声道4.0.12。C#winform应用程序

代码:

public class DataGridViewStudyReference : CustomControls.DataGridViewDataEntry<StudyRefrenceValueBusinessObjectNew>
{ 
}

public class DataGridViewDataEntry<BindingSourceType> : DataGridView
{
        public void ResetDataSource()
        {
            if (DataEntrySource == null)
            {
                DataEntrySource = new BindingList<BindingSourceType>();
                this.DataSource = DataEntrySource;
            }
            else
            {
                DataEntrySource.Clear();
            }
        }
}

public class StudyRefrenceValueBusinessObjectNew
{
    public long StudyReferenceID { get; set; }

    public long StudyID { get; set; }

    public int GenderValue { get; set; }

    public int AgeInitial { get; set; }

    public int AgeFinal { get; set; }

    public string TextValue { get; set; }

    public int ValueInitial { get; set; }

    public int ValueFinal { get; set; }

}
公共类DataGridViewStudyReference:CustomControls.DataGridViewDataEntry
{ 
}
公共类DataGridViewDataEntry:DataGridView
{
public void ResetDataSource()
{
如果(DataEntrySource==null)
{
DataEntrySource=new BindingList();
this.DataSource=DataEntrySource;
}
其他的
{
DataEntrySource.Clear();
}
}
}
公共类学习RefresenceValueBusinessObjectNew
{
公共长时间学习引用ID{get;set;}
公共长时间学习ID{get;set;}
public int GenderValue{get;set;}
public int AgeInitial{get;set;}
public int AgeFinal{get;set;}
公共字符串TextValue{get;set;}
public int ValueInitial{get;set;}
public int ValueFinal{get;set;}
}
完整的异常详细信息如下所示

信息:

索引小于0或大于或等于列表计数。 参数名称:索引1

堆栈跟踪:

  at System.Collections.ArrayList.ThrowNewArgumentOutOfRangeException (System.String name, System.Object actual, System.String message) [0x00000] in <filename unknown>:0 
  at System.Collections.ArrayList.get_Item (Int32 index) [0x00000] in <filename unknown>:0 
  at System.Windows.Forms.DataGridViewCellCollection.get_Item (Int32 index) [0x00000] in <filename unknown>:0 
  at (wrapper remoting-invoke-with-check) System.Windows.Forms.DataGridViewCellCollection:get_Item (int)
  at System.Windows.Forms.DataGridView.CalculateColumnCellWidth (Int32 index, DataGridViewAutoSizeColumnMode mode) [0x00000] in <filename unknown>:0 
  at System.Windows.Forms.DataGridView.AutoResizeColumnInternal (Int32 columnIndex, DataGridViewAutoSizeColumnMode mode) [0x00000] in <filename unknown>:0 
  at System.Windows.Forms.DataGridView.AutoResizeColumnsInternal () [0x00000] in <filename unknown>:0 
  at System.Windows.Forms.DataGridView.OnColumnAddedInternal (System.Windows.Forms.DataGridViewColumnEventArgs e) [0x00000] in <filename unknown>:0 
  at System.Windows.Forms.DataGridView.OnColumnCollectionChanged (System.Object sender, System.ComponentModel.CollectionChangeEventArgs e) [0x00000] in <filename unknown>:0 
  at System.Windows.Forms.DataGridViewColumnCollection.OnCollectionChanged (System.ComponentModel.CollectionChangeEventArgs e) [0x00000] in <filename unknown>:0 
  at System.Windows.Forms.DataGridViewColumnCollection.Add (System.Windows.Forms.DataGridViewColumn dataGridViewColumn) [0x00000] in <filename unknown>:0 
  at System.Windows.Forms.DataGridView.DoBinding () [0x00000] in <filename unknown>:0 
  at System.Windows.Forms.DataGridView.ReBind () [0x00000] in <filename unknown>:0 
  at System.Windows.Forms.DataGridView.set_DataSource (System.Object value) [0x00000] in <filename unknown>:0 
  at LabManagement.WinForm.CustomControls.DataGridViewDataEntry`1[LabManagement.Model.Study.StudyRefrenceValueBusinessObjectNew].ResetDataSource () [0x00020] in /home/alit/Projects/LabManagementSolution/LabManagement/LabManagement.WinForm/CustomControls/DataGridViewDataEntry.cs:64 
位于System.Collections.ArrayList.ThrownewargumEntotofrangeException(System.String名称、System.Object实际值、System.String消息)[0x00000]中:0
在System.Collections.ArrayList.get_项(Int32索引)[0x00000]中:0
在System.Windows.Forms.DataGridViewCellCollection.get_项(Int32索引)[0x00000]中:0
at(包装器远程处理调用检查)System.Windows.Forms.DataGridViewCellCollection:get_Item(int)
0中的System.Windows.Forms.DataGridView.CalculateColumnCellWidth(Int32索引,DataGridViewAutoSizeColumnMode模式)[0x00000]处
在System.Windows.Forms.DataGridView.AutoResizeColumnInternal(Int32 columnIndex,DataGridViewAutoSizeColumnMode模式)[0x00000]中:0
位于:0中的System.Windows.Forms.DataGridView.AutoResizeColumnSternal()[0x00000]处
在System.Windows.Forms.DataGridView.OnColumnAddedIn内部(System.Windows.Forms.DataGridViewColumnEventArgs e)[0x00000]中:0
在System.Windows.Forms.DataGridView.OnColumnCollectionChanged(System.Object sender,System.ComponentModel.CollectionChangeEventArgs e)[0x00000]中:0
0中的System.Windows.Forms.DataGridViewColumnCollection.OnCollectionChanged(System.ComponentModel.CollectionChangeEventArgs e)[0x00000]处
在:0中的System.Windows.Forms.DataGridViewColumnCollection.Add(System.Windows.Forms.DataGridViewColumn DataGridViewColumn)[0x00000]处
位于:0中的System.Windows.Forms.DataGridView.DoBinding()[0x00000]处
在System.Windows.Forms.DataGridView.ReBind()[0x00000]中:0
在System.Windows.Forms.DataGridView.set_数据源(System.Object值)[0x00000]中:0
在LabManagement.WinForm.CustomControls.DataGridViewDataEntry`1[LabManagement.Model.Study.studyRefresenceValueBusinessObjectNew].ResetDataSource()[0x00020]中的/home/alit/Projects/LabManagementSolution/LabManagement/LabManagement.WinForm/CustomControls/DataGridViewDataEntry.cs:64

谁能帮我一下,为什么会发生这种异常?

我知道了问题的原因

在我的DataGridView中,
AutoSizeColumnsMode
模式被设置为
AllCell
我将其更改为
None
。然后,此错误被删除。 mono框架中的列大小计算似乎存在一些内部问题,我认为这是mono框架的一个缺陷。但是现在我的问题已经解决了