单击数据网格视图中的信息后程序停止响应

Program stops responding after clicking on information in Data Grid View

每次我在我的数据网格视图程序中单击任何用户时都会停止响应并给我一个错误,告诉我“System.ArgumentOutOfRangeException:'Index was out of range. Must be non-negative and less than the size of the collection. Arg_ParamName_Name'”向我显示此错误的部分是

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

尝试

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

已更新 抱歉,您需要先投出旧合集