简体   繁体   中英

Program stops responding after clicking on information in Data Grid View

每次我点击数据网格视图程序中的任何用户时,都会停止响应并给我一个错误,告诉我“System.ArgumentOutOfRangeException:'索引超出范围。必须为非负且小于集合的大小。Arg_ParamName_Name' “向我显示此错误的部分是

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

Try

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

Updated Old Collection you'll need to cast first sorry

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM