We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Bold font in GDBD cell

How do I set the style property of a particular cell in the GridDataBoundGrid control to bold? I''m trying to set this through the e.Style property of the Syncfusion.Windows.Forms.Grid.GridPrepareViewStyleInfoEventArgs type e.

5 Replies

AD Administrator Syncfusion Team August 24, 2005 09:16 AM UTC

PrepareViewStyleInfo is the way to try to set cell specific properties in a GridDataBoundGrid. Here is code that worked for me.
private void gridDataBoundGrid1_PrepareViewStyleInfo(object sender, GridPrepareViewStyleInfoEventArgs e)
{
	int col = this.gridDataBoundGrid1.Binder.NameToColIndex("Col2");
	if(e.ColIndex == col && e.RowIndex == 2)
	{
		e.Style.Font.Bold = true;
	}
}


            


AP Atith Pagdi August 24, 2005 12:51 PM UTC

This is my code for the PrepareViewStyleInfo event. private void dgEx_PrepareViewStyleInfo(object sender, Syncfusion.Windows.Forms.Grid.GridPrepareViewStyleInfoEventArgs e) { #region Header Formatting if (e.ColIndex == 0) { e.Style.CellType = GridTableCellType.None.ToString(); e.Style.Text = ""; e.Style.Themed = false; e.Style.Enabled = false; } //If it''s a header row, then we need to make some invisible. if (e.Style.CellType == GridTableCellType.ColumnHeaderCell.ToString() && e.Style.CellIdentity != null) { //Rep(s) if (e.RowIndex == 3 && e.ColIndex == 1) { e.Style.CellType = GridTableCellType.None.ToString(); e.Style.Text = ""; e.Style.Themed = false; e.Style.Enabled = false; } //Team Leads if (e.RowIndex == 3 && e.ColIndex == 4) { e.Style.CellType = GridTableCellType.None.ToString(); e.Style.Text = ""; e.Style.Themed = false; e.Style.Enabled = false; } //Hours Assigned if (e.RowIndex == 3 && e.ColIndex == 7) { e.Style.CellType = GridTableCellType.None.ToString(); e.Style.Text = ""; e.Style.Themed = false; e.Style.Enabled = false; } //Exclusion Comments if (e.RowIndex == 4 && e.ColIndex == 1) { e.Style.CellType = GridTableCellType.None.ToString(); e.Style.Text = ""; e.Style.Themed = false; e.Style.Enabled = false; } //Comments if (e.RowIndex == 5 && e.ColIndex == 1) { e.Style.CellType = GridTableCellType.None.ToString(); e.Style.Text = ""; e.Style.Themed = false; e.Style.Enabled = false; } //Dummy rows if ((e.RowIndex == 0 || e.RowIndex == 2) && e.ColIndex >= 2 && e.ColIndex <= 13) { e.Style.CellType = GridTableCellType.None.ToString(); e.Style.Text = ""; e.Style.Themed = false; e.Style.Enabled = false; } if (e.RowIndex == 3 && e.ColIndex >= 9 && e.ColIndex <= 13) { e.Style.CellType = GridTableCellType.None.ToString(); e.Style.Text = ""; e.Style.Themed = false; e.Style.Enabled = false; } } #endregion #region General Formatting GridDataBoundGrid grid = sender as GridDataBoundGrid; if (grid != null && e.RowIndex > grid.Model.Rows.HeaderCount && e.ColIndex > grid.Model.Cols.HeaderCount) { if (grid.IsShowCurrentRow(e.RowIndex) && !grid.CurrentCell.HasCurrentCellAt(e.RowIndex, e.ColIndex)) { e.Style.BackColor = SystemColors.Highlight; e.Style.TextColor = SystemColors.HighlightText; } else { e.Style.BackColor = Color.FromArgb( 219, 226, 242 ); } } #endregion #region Colour Formatting CurrencyManager cm = (CurrencyManager)this.BindingContext[this.dgTest.DataSource, DAF_EXCL_REPORT]; DataRow dr = ((DataRowView)cm.Current).Row; if (e.RowIndex > 5) { //Status date, status, product if ((e.RowIndex % 6 == 0 || e.RowIndex % 6 == 1 || e.RowIndex % 6 == 2) && e.ColIndex == 1) { if (dr[COL_IS_PUBLIC_PROJECT].ToString().Equals("N")) e.Style.TextColor = Color.SaddleBrown; } //Target, Acquirer if(e.RowIndex % 6 == 1 && (e.ColIndex == 2 || e.ColIndex == 5)) { if (dr[COL_IS_PUBLIC_PROJECT].ToString().Equals("N")) e.Style.TextColor = Color.SaddleBrown; if (dr[COL_PROJECT_SIDE].ToString().Equals("Buy") && e.ColIndex == 2) { e.Style.Font.Bold = true; } if (dr[COL_PROJECT_SIDE].ToString().Equals("Selll") && e.ColIndex == 5) { e.Style.Font.Bold = true; } } //Equity, aggregate consideration if (e.RowIndex % 6 == 1 && (e.ColIndex == 8 || e.ColIndex == 9)) { if (dr[COL_IS_PUBLIC_SIZE].ToString().Equals("N")) e.Style.TextColor = Color.SaddleBrown; } //Advisory, total fees if (e.RowIndex % 6 == 1 && (e.ColIndex == 10 || e.ColIndex == 11)) { if (dr[COL_IS_PUBLIC_FEE].ToString().Equals("N")) e.Style.TextColor = Color.SaddleBrown; } //Percentage if (e.RowIndex % 6 == 1 && (e.ColIndex == 12 || e.ColIndex == 13)) { if (dr[COL_IS_PUBLIC_FEE].ToString().Equals("N") && dr[COL_IS_PUBLIC_SIZE].ToString().Equals("N")) e.Style.TextColor = Color.SaddleBrown; } } #endregion } The problem I have is that when I alternate between records (it''s a multi row record), the settings go awry and behave in a haphazard manner in that, rows that show up as brown first up, after selection of some other rows turn to black. A similar thing happens with the bolded cells. Could this be because I''m using the currency manager class? Am I using this class correctly? Please let me know, since the formatting needs to be static... and not behave in a haphazard manner. If you could look at the code and get back to me on this, it''d be great. Thanks.


AD Administrator Syncfusion Team August 24, 2005 01:22 PM UTC

Is your calculation e.RowIndex % 6 picking out the proper rows? Do you need to use something like (e.RowIndex-grid.Model.Rows.HeaderCount) % 6 to pick out the rows 6 units apart under the 6 header? Is the problem strcitly a refresh problem, meaning that if you minimize and then maximize the form, the grid draws correctly? If so, then when you want to trigger a color change, you have to make sure you call grid.Refresh, passing in the whole 6 row range that needs to be refreshed. If you can upload a sample project showing the problem, we can try debugging it here.


AP Atith Pagdi August 24, 2005 03:55 PM UTC

Yes, the row and col index values point to the right cells. But why should the the appearance change and the PrepareViewStyleInfo event be triggered even when the user merely SELECTS a row? And even if it is, why is the code I''ve written changing the attributes of a cell that was previously rendered correctly? Is it that the whole routine is executed for EVERY cell in the DGBG? Thanks.


AD Administrator Syncfusion Team August 24, 2005 04:57 PM UTC

PrepareViewStyleInfo is hit many, many, many times. Everytime the cell is drawn it is hit. This means if you select a row, the PrepareViewStyleInfo will be raised for every cell in that row. Any time the cell is repainted for any reason, this event is hit. Exactly what pieces of your code get hit inside PrepareViewStyleInfo depend on how you structure it with your if-statements.

Loader.
Live Chat Icon For mobile
Up arrow icon