Like this:
public void BindData()
{
radGridView.Columns.Clear();
if ((SystemLookUpModel)DataContext == null) return;
GridViewDataColumn gc = new GridViewDataColumn();
gc.Header =
"Option";
gc.UniqueName =
"Name";
gc.DataMemberBinding =
new Binding("Name");
radGridView.Columns.Add(gc);
foreach (SystemLookUp slu in ((SystemLookUpModel)DataContext).ProgramType.SystemLookUp)
{
NumericUpDownColumn gc2 = new NumericUpDownColumn();
gc2.Header = slu.Name;
gc2.UniqueName =
string.Format("ProgramID{0}", slu.ID);
gc2.DataMemberBinding =
new Binding(gc2.UniqueName);
radGridView.Columns.Add(gc2);
}
LoadRows();
}
private void LoadRows()
{
IList list = (IList)((SystemLookUpModel)DataContext).GetServiceInProgramsDataSource();
radGridView.ItemsSource = list;
radGridView.SelectedItem = list.Count == 0 ?
null : list[0];
}
I am adding rows with button add like this:
private void btnAdd_Click(object sender, RoutedEventArgs e)
{
radGridView.BeginInsert();
}
The problem: sometimes, only when grid got focus, but not the first time, when I press Add button, I got the Exception:
Specified argument was out of the range of valid values. Parameter name: index
It is thrown 2 times, one after another. The new row created and selected, but it does not enter the edit mode. If I manually double-click it it works OK.
Can you help me with this problem?