Jump to content
  • Revista PROGRAMAR: Já está disponível a edição #60 da revista programar. Faz já o download aqui!

Sign in to follow this  
ProgramadoraR

[Resolvido] Linha DataGridView

Recommended Posts

ProgramadoraR

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?

Share this post


Link to post
Share on other sites
rezanov

Experimenta adicionar antes o evento

this.dataGridView1.RowPrePaint += new DataGridViewRowPrePaintEventHandler(dataGridView1_RowPrePaint);

Share this post


Link to post
Share on other sites
ProgramadoraR

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

Share this post


Link to post
Share on other sites
rezanov

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;
		    }
	    }
    }

Share this post


Link to post
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
Sign in to follow this  

×

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.