Jump to content

[Resolvido] Linha DataGridView


ProgramadoraR

Recommended Posts

Boas, eu criei um evento (CellContentClick) no datagridview para quando uma coluna for igual a 0 aparecer essa linha a vermelho

e para isso utilizei o seguinte codigo:

Código (C#):

private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)

{

if (e.Value != null && e.ColumnIndex == 12 && e.Value.Equals("0"))

{

DataGridViewColumn row = dataGridView1.Columns[e.ColumnIndex];

row.DefaultCellStyle.ForeColor = Color.Red;

}

}

Mas nao funciona, como é que eu posso fazer?

Link to comment
Share on other sites

mas dá-me este erro: 'System.Windows.Forms.DataGridViewCellEventArgs' does not contain a definition for 'Value' and no extension method 'Value' accepting a first argument of type 'System.Windows.Forms.DataGridViewCellEventArgs' could be found (are you missing a using directive or an assembly reference?)

Edited by ProgramadoraR
Link to comment
Share on other sites

um exemplo simples

void dataGridView1_RowPrePaint(object sender, DataGridViewRowPrePaintEventArgs e)
    {
	    if (!string.IsNullOrEmpty(dataGridView1.Rows[e.RowIndex].Cells[12].Value.ToString()))
	    {
		    if (Convert.ToInt32(dataGridView1.Rows[e.RowIndex].Cells[12].Value.ToString()) <= 0)
		    {
			    dataGridView1.Rows[e.RowIndex].DefaultCellStyle.BackColor = Color.Red;
		    }
		    else
		    {
			    dataGridView1.Rows[e.RowIndex].DefaultCellStyle.BackColor = Color.White;
		    }
	    }
    }
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.