0
First of all thank you for your time.
I have a question:
I have a Datagridview dgvPessoa filled with a Datatable.
Example:
I want you to select when right-click and not left-click, and pick the index of the line clicked.
Method to change the color of the clicked line:
private void PintarFundoDGV(DataGridView dgv, linhaClicada)
{
if (dgv.CurrentRow.DefaultCellStyle.BackColor == Color.Transparent)
{
dgv.CurrentRow.DefaultCellStyle.BackColor = Color.Red;
dgv.Rows[linhaClicada].DefaultCellStyle.BackColor =
Color.Transparent;
}
}
It would change the color in the mouse click event with the right button.
Catch the id
and call the method
private void dgvLocacao_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e)
{
if (e.Button != MouseButtons.Right)
{
return;
}
else
{
if (dgvLocacao.CurrentCell == null)
{
return;
}
else
{
id = dgvLocacao.Rows[dgvLocacao.CurrentRow.Index].Cells[ID_LOCACAO.Name].Value.toInt32();
PintarFundoDGV(dgvMeuDataGridBiew, id);
}
}
}
Hi @Gustavo. Post the code you are using, it will be easier to help.
– João Martins
So I couldn’t remove the part of taking the selection with the left. I don’t want to select, just click on the line with the right button that will open a Contexmenustrip and the line will turn red, to paint the background I use this method: > private void Pintarfundodgv(Datagridview dgv) { if (dgv.CurrentRow.Defaultcellstyle.Backcolor == Color.Transparent) { dgv.CurrentRow.Defaultcellstyle.Backcolor = Color.Red; } }
– Gustavo Pedro
Edit your question and put there the structured code. In comment it is difficult to notice the sequence.
– João Martins
I hope you can understand I think you’re still confused I think what I want is simple, but I have no idea how to do it
– Gustavo Pedro