使用c#.net删除datagridview中选定行的显示确认消息框 [英] display confirm message box on delete selected row in datagridview using c#.net
本文介绍了使用c#.net删除datagridview中选定行的显示确认消息框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
解决方案
显示确认消息框> if (DialogResult.Yes == MessageBox.Show( 你想要删除吗?, 确认,MessageBoxButtons.YesNo,MessageBoxIcon.Warning))
{
// 做你想做的事情
}
将datagridview的 UserCanDeleteRow 属性设置为 false
现在单击单击datagridview事件
检查 e.ColumnIndex 等于deletebtnColumn的列索引
然后...显示消息对话框..
DialogResult dr = Messagebox.Show( < span class =code-string >您确定要删除行吗?, 确认,MessageboxButtons.YesNo );
if (dr == DialogResult.Yes)
{
// 从数据库或datagridview中删除行...
}
else < span class =code-keyword> if (dialogResult == DialogResult.No)
{
// 无事可做
}
快乐编码!
:)
string colName = dgvGlInfo.Columns [e.ColumnIndex] .Name;
if (colName == 删除)
{
DialogResult result = MessageBox.Show( 你真的想删除???,
确认产品删除,
MessageBoxButtons.YesNo,MessageBoxIcon.Warning);
if (result == DialogResult.Yes)
{
dgvGlInfo.Rows.RemoveAt(e.RowIndex);
lstTransDetails.RemoveAt(e.RowIndex);
MessageBox.Show( 已删除);
}
}
>
display confirm message box on delete selected row in datagridview using c#.net
解决方案
if (DialogResult.Yes == MessageBox.Show("Do You Want Delete ?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Warning)) { // do what u want }
set datagridview's UserCanDeleteRow Property to false
Now in cell click event of datagridview
Check e.ColumnIndex is equal to column index of deletebtnColumn
then... show message dialog..
DialogResult dr = Messagebox.Show("Are you sure to delete row?","Confirmation",MessageboxButtons.YesNo); if (dr == DialogResult.Yes) { //delete row from database or datagridview... } else if (dialogResult == DialogResult.No) { //Nothing to do }
Happy Coding!
:)
string colName = dgvGlInfo.Columns[e.ColumnIndex].Name; if (colName == "Remove") { DialogResult result = MessageBox.Show("Do you really want to Remove ???", "Confirm product deletion", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (result == DialogResult.Yes) { dgvGlInfo.Rows.RemoveAt(e.RowIndex); lstTransDetails.RemoveAt(e.RowIndex); MessageBox.Show("Removed"); } }>
这篇关于使用c#.net删除datagridview中选定行的显示确认消息框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文