如何使用devexpress中的复选框删除所选数据...我使用VS2013和devexpress 14.2。在我的属性gridView1中设置
OptionSelection:
MultiSelect = true
MultiSelectMode = CheckBoxRowSelect
ResetSelectionClickOutsideCheckbox = true
这是我删除方法的代码:
private void DeleteContact()
{
try
{
if (gridView1.DataRowCount == 0)
{
MessageBox.Show("DATA MASIH KOSONG");
}
else
{
if (MessageBox.Show("Apakah Kamu ingin menghapus data ini?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
{
//membuat koneksi_manual
if (koneksi_manual.con.State == ConnectionState.Open)
{
koneksi_manual.con.Close();
}
koneksi_manual.con.Open();
//koneksi_manual.con.Open();
OracleCommand cmd = new OracleCommand();
// Get your currently selected grid row
var rowHandle = gridView1.FocusedRowHandle;
// Get the value for the given column - convert to the type you're expecting
var obj = gridView1.GetRowCellValue(rowHandle, "NAMA");
//koneksi_manual.con.Open();
cmd.CommandText = "DELETE FROM CONTACT WHERE NAMA = '" + obj + "'";
cmd.Connection = koneksi_manual.con;
cmd.ExecuteNonQuery();
//koneksi_manual.con.Close();
}
}
}
catch (Exception ex)
{
// Memunculkan pesan error
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
完全
var obj = gridView1.GetRowCellValue(rowHandle,“NAMA”);
这只是来自gridView1的getvalue来删除数据。我不知道如何删除gridcontrol中使用的复选框。
有人可以帮助或建议我吗? 感谢
答案 0 :(得分:0)
而不是gridView1.FocusedRowHandle;
,使用gridView1.GetSelectedRows;
,它返回一个表示所选行句柄的整数值数组。
foreach(var rowHandle in gridView1.GetSelectedRows()){
...
}