Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CellFormatting Event - When Column is NOT Visible?

Status
Not open for further replies.

eb24

Programmer
Dec 17, 2003
240
0
0
US
I am using C# 2.0 in a Windows Forms platform - I am using the CellFormatting() Event to display certain rows of my DataGridView with a certain color depending on the value found in a certain column. This works great if the Column is Visible, but I don't want to display this Column to the end users! Is there a way to do this?

This column has a Security flag that basically says Access or No Access and depending on these two values, it colors the Rows accordingly.

Thanks for any advice!
 
Try setting the Visible=true and width=0 of the coulmn.

________________________________________________________
Zameer Abdulla
Help to find Missing people
 
Zameer:

Thanks for responding but I've tried that already and having the .Width = 0, one can still see the column with a very small width. By having the Width = 0, as the user tabs through the cells, the Tab Stops within this small column, which I do not want.

Any other suggestions anyone?
 
This is working for me
Code:
this.DataGridView1.Columns(2).Visible == false
Code:
{ 
    int x; 
    for (x = 0; x <= this.DataGridView1.Rows.Count - 1; x++) { 
        if (this.DataGridView1.Rows(x).Cells(2).Value == 3) { 
            this.DataGridView1.Rows(x).DefaultCellStyle.BackColor = Color.Red; 
        } 
    } 
}


________________________________________________________
Zameer Abdulla
Help to find Missing people
 
Where do you have that second piece of code? Within a _CellFormatting Event?

FYI, I have the following and does not work:
Code:
private void dgv_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
  if (this.dgv.Columns[e.ColumnIndex].Name == "SecType")
  {
    if (e.Value.ToString() == "Access"))
    {
      dgv.Rows[e.RowIndex].DefaultCellStyle.BackColor = Color.Red;
    }
  }
}
 
I have nothing other than loop through the rows.

________________________________________________________
Zameer Abdulla
Help to find Missing people
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top