dimanche 3 mai 2015

Delete Selected data using checkbox in gridcontrol devexpress?

Delete Selected Data CheckBox

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




Aucun commentaire:

Enregistrer un commentaire