Home > Blockchain >  Program stops responding after clicking on information in Data Grid View
Program stops responding after clicking on information in Data Grid View

Time:10-26

everytime I click on any user in my Data Grid View program stops responding and gives me an error that tells me "System.ArgumentOutOfRangeException: 'Index was out of range. Must be non-negative and less than the size of the collection. Arg_ParamName_Name'" The part that shows me this error is

VartotojoID.Text = VartotojuDGV.SelectedRows[0].Cells[0].Value.ToString();

CodePudding user response:

Try

VartotojoID.Text = VartotojuDGV.SelectedRows.Cast<DataGridViewRow>().FirstOrDefault()?.Cells[0].Value.ToString();

Updated Old Collection you'll need to cast first sorry

  • Related