本文介绍了Dalete在Windows Appps中从DataGridView中选择了行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我有一个dataGridView和每行的单元格索引零(0)中的按钮。每当我点击按钮时,应该从DataGridView中删除所属行。 我正在做, private void GvSales_CellEnter( object sender,DataGridViewCellEventArgs e) { if (e.ColumnIndex == 0 ) { // DataGridViewRow row = GvSales.CurrentRow; GvSales.Rows.Remove(GvSales.Rows [e.RowIndex]); } } 但是它给出了例外......操作不能在此事件处理程序中执行解决方案 我建​​议使用以下代码处理网格CellClick事件(而不是CellEnter): 私有 void GvSales_CellClick( object sender,DataGridViewCellEventArgs e) { if (e.ColumnIndex == 0 && e.RowIndex < GvSales.Rows.Count) GvSales.Rows.RemoveAt(e.RowIndex); } +: 没有试用/捕获块 更有效删除 我相信它会正常工作.... private void GvSales_CellMouseClick( object sender,DataGridViewCellMouseEventArgs e) { 尝试 { if (e.ColumnIndex == 0 ) // 创建列索引(删除按钮) { GvSales.Rows.Remove(GvSales.Rows [e.RowIndex]); } } catch { } 最后 { } } i have a dataGridView and a button in cell index Zero(0) of each row . whenever i click button the belonging row should be deleted from DataGridView.I am doing ,private void GvSales_CellEnter(object sender, DataGridViewCellEventArgs e) { if (e.ColumnIndex == 0) { // DataGridViewRow row = GvSales.CurrentRow; GvSales.Rows.Remove(GvSales.Rows[e.RowIndex]); } }but it gives Exception...... Operation Cannot be performed in this event handler 解决方案 I suggest to handle grid CellClick event (instead of CellEnter) with the following code:private void GvSales_CellClick(object sender, DataGridViewCellEventArgs e) { if (e.ColumnIndex == 0 && e.RowIndex < GvSales.Rows.Count) GvSales.Rows.RemoveAt(e.RowIndex); }"+":without try/catch blockmore effective removingi am sure it will work fine....private void GvSales_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e) { try { if (e.ColumnIndex == 0)// created column index (delete button) { GvSales.Rows.Remove(GvSales.Rows[e.RowIndex]); } } catch { } finally { } } 这篇关于Dalete在Windows Appps中从DataGridView中选择了行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
07-12 01:17