-1
Good morning. I need help to solve the following problem: I need to do a project in which I insert a code and name of a person to be stored in a datagridview (windows Forms c#), but when I use the following line that was passed to me for help, ends up giving error when I click the same button to remove even if I have no Row or selected cell, I would like help to create a if to prevent or to send a message to the person who presses the button when no cell is selected.
private void BtnLimparDados_Click(object sender, EventArgs e)
{
txtCodigo.Text = "";
txtNome.Text = "";
}
private void button2_Click(object sender, EventArgs e)
{
this.Close();
}
private void btnAdicionar_Click(object sender, EventArgs e)
{
dgvDados.Rows.Add(txtCodigo.Text, txtNome.Text);
txtCodigo.Text = "";
txtNome.Text = "";
txtNome.Focus();
}
private void btnRemover_Click(object sender, EventArgs e)
{
int row = dgvDados.CurrentCell.RowIndex;
if (dgvDados.CurrentCell.RowIndex == -1)
{
MessageBox.Show("a", "a", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
}
else
dgvDados.Rows.RemoveAt(row);
}
private void dgvDados_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
{
int row = e.RowIndex;
dgvDados.Rows.RemoveAt(row);
}
}
}