0

I already searched for a solution on this topic. However, I was unable to find one. I trying to implement the solution answer for this question, however when adding a new row to the datagrid, I get "System.ArgumentOutOfRangeException: 'Index was out of range. Must be non-negative and less than the size of the collection.'" error. after the new row was inserted and the program returned to the previously selected row before inserting a new value.

private void Datagrid_Registro_SelectedCellsChanged(object sender, SelectedCellsChangedEventArgs e)
{
Registro.RegistroItems row =(Registro.RegistroItems)Datagrid_Registro.SelectedItems[0];

textbox_DocIdentidad.Text = row.DocumentoIdentidad;
comboBox_Ubicaciones.SelectedItem = row.AreaDestino;
textbox_CarnetAsignado.Text = row.CarnetAsignado;
}
dsalas
  • 139
  • 1
  • 2
  • 8
  • 2
    Ask yourself - what happens on the first line of code when I de-select all of the items and the size of the SelectedItems list is 0? – hoodaticus Jul 21 '17 at 20:17
  • Thank you for pointing me to the right direction. I´ve solved the problem using an if statement evaluating the selectedItems.count property not equal to 0. @hoodaticus – dsalas Jul 24 '17 at 12:35

0 Answers0