dimanche 22 octobre 2017

Preventing from Deleting a Row

Hi I just created a Data Grid View and a delete button that deletes a row. However, I accidentally click the delete button even though there's no data inserted. Application breakmode appears. What I did is I created a If-else statement to prevent that from happening. But I cant get it right.

private void button5_Click(object sender, EventArgs e)
    {


        if (dataGridView1.RowCount.=0)
        {
            MessageBox.Show("Nothing to Delete");
            return;

        }
        else
        {
            MessageBox.Show("Are you sure you want to delete the selected items?", "Students_Records",
            MessageBoxButtons.OKCancel);
            studentsBindingSource.RemoveCurrent();
        }
    }

I always get this Error: CS1001 Identifier expected

Note (I'm a newbie)

Aucun commentaire:

Enregistrer un commentaire