简体   繁体   中英

Delete Selected data using checkbox in gridcontrol devexpress?

删除所选数据复选框

How can i delete selected data using checkbox in devexpress...i used VS2013 and devexpress 14.2 . In My Property gridView1 I set

OptionSelection :

MultiSelect = true
MultiSelectMode = CheckBoxRowSelect
ResetSelectionClickOutsideCheckbox = true

Here the codes of my Delete Method:

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);
            }
        }

exactly

var obj = gridView1.GetRowCellValue(rowHandle, "NAMA");

this just getvalue from gridView1 to delete the data. i didn't know how to delete where used checkbox in gridcontrol.

Someone can help or suggest me ? Thanks

instead of gridView1.FocusedRowHandle; , use gridView1.GetSelectedRows; , which returns an array of integer values representing the handles of the selected rows.

foreach(var rowHandle in gridView1.GetSelectedRows()){

 ...

}

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