It seems that Style.Reset() doesn't truly reset everything. Code is below, results are attached. Notice the black borders on the top two rows. The value in the have columns for both of those rows was 0, then via code (UI technically), the number is updated to the same as the need column, going from a red border to the black border. The third row down which appears as I would like it always had have > need, so it was never changed, and has the defaults.
And while I have your attention I have two other related questions:
1) Is there a better way to access the style element of a cell than this?
GridViewCellInfo haveCell = e.RowElement.RowInfo.Cells["HaveColumn"];
2) I just wanted a simple 2 pixel red border...I've seen conflicting information in the forums as to what's really required. The smallest set of properties I found that would work are in the code below. That seems like an awful lot of work to put a 2 pixel red border in place. Is what I have the best approach?
private void RequirementsGrid_RowFormatting(object sender, RowFormattingEventArgs e)
{
GridViewCellInfo haveCell = e.RowElement.RowInfo.Cells["HaveColumn"];
int? need = (int?)e.RowElement.RowInfo.Cells["NeedColumn"].Value;
int have = 0;
if (haveCell.Value != null)
int.TryParse(haveCell.Value.ToString(), out have);
if (have < need)
{
haveCell.Style.CustomizeBorder = true;
haveCell.Style.BorderColor = Color.Red;
haveCell.Style.BorderGradientStyle = GradientStyles.Solid;
haveCell.Style.BorderBoxStyle = BorderBoxStyle.SingleBorder;
haveCell.Style.BorderWidth = 2;
}
else
{
haveCell.Style.Reset();
}
}
Thanks!
And while I have your attention I have two other related questions:
1) Is there a better way to access the style element of a cell than this?
GridViewCellInfo haveCell = e.RowElement.RowInfo.Cells["HaveColumn"];
2) I just wanted a simple 2 pixel red border...I've seen conflicting information in the forums as to what's really required. The smallest set of properties I found that would work are in the code below. That seems like an awful lot of work to put a 2 pixel red border in place. Is what I have the best approach?
private void RequirementsGrid_RowFormatting(object sender, RowFormattingEventArgs e)
{
GridViewCellInfo haveCell = e.RowElement.RowInfo.Cells["HaveColumn"];
int? need = (int?)e.RowElement.RowInfo.Cells["NeedColumn"].Value;
int have = 0;
if (haveCell.Value != null)
int.TryParse(haveCell.Value.ToString(), out have);
if (have < need)
{
haveCell.Style.CustomizeBorder = true;
haveCell.Style.BorderColor = Color.Red;
haveCell.Style.BorderGradientStyle = GradientStyles.Solid;
haveCell.Style.BorderBoxStyle = BorderBoxStyle.SingleBorder;
haveCell.Style.BorderWidth = 2;
}
else
{
haveCell.Style.Reset();
}
}
Thanks!