Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
325
ArgumentOutOfRangeException is thrown when initializing in XamGrid.
posted

public void InitDataGrid()
{
// [Grid 속성]
{
this.xDataGrid.HeaderHeight = 50;
this.xDataGrid.AutoGenerateColumns = false;
this.xDataGrid.DefaultColumnMinWidth = 100;
this.xDataGrid.HeaderClickAction = HeaderClickAction.SortByOneColumnOnly;
this.xDataGrid.RowHeight = 50;
this.xDataGrid.RowSelectionAnimationMode = RowSelectionAnimationMode.ColorBlend;
this.xDataGrid.RowSeparatorHeight = 2;
this.xDataGrid.SelectionMode = GridSelectionMode.SingleRow;
}

//this.m_DataGrid.SelectedItemsChanged += Grid_SelectedItemsChanged;
this.xDataGrid.CellClicked += delegate (object sender, GridCellEventArgs args)
{
AudioPlayer.PlayClickSound();
args.Grid.SortDescriptions.Clear();
};

ClearDataGrid();
this.xDataGrid.ItemsSource = this.m_Model.SpectrumMeasureData;
}

public void ClearDataGrid()
{
// [Grid Headr 초기 세팅]
this.xDataGrid.Columns.Clear();
this.m_Model.SpectrumMeasureData.Clear();


// [Wave header 생성]
Column Wavelength = GridUtil.Instance.SetColumn(ColumnTypes.Text, "Wave", "Wavelength", new ColumnWidth() { Value = 150 });
this.xDataGrid.Columns.Add(Wavelength);


// [파장값 입력]
this.m_Model.InitMeasureSetup();
foreach (var wave in this.m_Model.WaveList)
{
SpectrumMeasureData Data = new SpectrumMeasureData();
Data.Wave = wave;
this.m_Model.SpectrumMeasureData.Add(Data);
}


// [차트 x축 초기화]
this.xDataChart.Series.Clear();
NumericXAxis xaxis = (NumericXAxis)this.xDataChart.Axes.FirstOrDefault(x => x is NumericXAxis);
xaxis.MinimumValue = this.m_Model.StartWave;
xaxis.MaximumValue = this.m_Model.EndWave;
xaxis.UpdateRange(true);
xaxis.ScrollRangeIntoView(xaxis.MinimumValue, xaxis.MaximumValue);

// [차트 y축 초기화]
NumericYAxis yaxis = (NumericYAxis)this.xDataChart.Axes.FirstOrDefault(x => x is NumericYAxis);
yaxis.MinimumValue = -5;
yaxis.MaximumValue = 5;
yaxis.UpdateRange(true);
yaxis.ScrollRangeIntoView(yaxis.MinimumValue, yaxis.MaximumValue);


this.xDataGrid.ScrollToColumnByIndex(0);
//this.xDataGrid.ItemsSource = this.m_Model.SpectrumMeasureData;
}

public class SpectrumMeasureData
{
public float Wave { get; set; }
public List<float> ABS
{
get; set;
} = new List<float>();


}

I put 10 grids in the beginning.
Then, call the ClearDataGrid() function and call the this.m_Model.SpectrumMeasureData.Add(Data); function to insert 5. In this case, ArgumentOutOfRangeException is thrown. It cannot be traced to the callstack.

Parents
No Data
Reply
  • 34830
    Offline posted

    Hello,

    I have been investigating into the behavior you are seeing in this case, and I am curious if you have a runnable sample project that you could share that reproduces this behavior or if you can provide the stack trace that describes the exception you are seeing here?

    It also may be worth noting that it seems like you are currently trying to add elements to a grid one-by-one that you are clearing the information / columns of while the grid is still bound. This may be less performant than if you would unhook the data source (set the ItemsSource to null), make the changes to your underlying data source, and then hook it back into the ItemsSource property of the grid. I suppose it is also possible that this could be a potential workaround to the exception you are seeing as well, but I have not yet been able to reproduce the behavior you are describing at the time of writing this.

    Please let me know if you have any other questions or concerns on this matter.

Children
No Data