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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Datagrid cell font color

Status
Not open for further replies.

tek1ket

MIS
Jan 25, 2009
70
IR

how can i change the font color of a specified Cell forexample named "VRequire" in some condtion ,for example when it is over 10?

private void StyleCalculateGrid()
{

DataGridTableStyle DcStyle=new DataGridTableStyle();
DcStyle.HeaderForeColor=Color.WhiteSmoke;
DcStyle.HeaderBackColor=Color.Blue;
DcStyle.HeaderFont= new Font("Verdana",10,FontStyle.Bold);


foreach(DataColumn dc in ds.Tables["TblCTVKnee"].Columns)
{
DataGridTextBoxColumn textColumn=new DataGridTextBoxColumn();
textColumn.MappingName= dc.ColumnName;
textColumn.HeaderText = dc.Caption;
if(dc.ColumnName.ToString()=="CoreNo")
textColumn.Width=0;
else if(dc.ColumnName.ToString()=="id_CTVknee")
textColumn.Width=0;
else if(dc.ColumnName.ToString()=="id_CT")
textColumn.Width=0;
else if(dc.ColumnName.ToString()=="id_proj")
textColumn.Width=0;
else
switch (cmbCtClass.Text.ToString())
{
case "TPY":
if(dc.ColumnName.ToString()=="CTVKnee")
{
textColumn.HeaderText="CT (Vknee)"; textColumn.Width=myDataGrid.Width/2-10;
}
else if (dc.ColumnName.ToString()=="VRequire")
{
textColumn.HeaderText="V Require"; textColumn.Width=myDataGrid.Width/2-10;
}
case "M":
if(dc.ColumnName.ToString()=="CTVKnee")
{ textColumn.HeaderText="CT (Vknee)"; textColumn.Width=0; } else if (dc.ColumnName.ToString()=="VRequire")
textColumn.Width=0;
else if (dc.ColumnName.ToString()=="SCMax") { textColumn.HeaderText="SC Max"; textColumn.Width=105; }
}
DcStyle.GridColumnStyles.Add(textColumn);
}
DcStyle.MappingName=ds.Tables["TblCTVKnee"].TableName;
if (myDataGrid.TableStyles.Count>0) myDataGrid.TableStyles.Clear();
myDataGrid.TableStyles.Add(DcStyle);
String Str ="id_CT= " + IdCT DataView mydataView = new DataView();
mydataView.Table = ds.Tables["TblCTVKnee"];
mydataView.RowFilter = Str;
myDataGrid.DataSource=mydataView;
myDataGrid.Refresh();
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top