Я просто хочу запустить проверку проверки, запущенную из события кнопки в форме. Для каждой строки внутри сетки она проверяет первую ячейку, чтобы увидеть, соответствует ли значение строке. Для каждого, кто терпит неудачу, я хочу, чтобы он изменил цвет ячейки или цвет фона строки как RED. Когда пользователь исправляет значение ячейки и снова нажимает кнопку, он вернется к цвету по умолчанию. Для жизни меня я не могу заставить ее изменить цвет. Я знаю, что есть событие для cellformatting, но, конечно, мне не нужно проходить событие, чтобы изменить стиль ячейки/строки. Я пытаюсь использовать код ниже без всякой удачи. Все примеры, которые я видел, основаны на событиях, поэтому надеюсь, что я смогу полностью избежать этого.
if (!ValidateParametersExistInScript(rtxtQuery.Text))
{
GridViewCellInfo cell = rgvNewParameters.Rows[0].Cells["ParameterName"];
cell.Style.BackColor = Color.Red;
cell.Style.DrawFill = true;
MessageBox.Show("Parameters do not match definition inside query, " +
"please check spelling and try again.");
}
Сначала вы должны установить CustomizeFill в значение true, прежде чем вы сможете изменить задний цвет GridViewCellInfo.
if (!ValidateParametersExistInScript(rtxtQuery.Text))
{
GridViewCellInfo cell = rgvNewParameters.Rows[0].Cells["ParameterName"];
cell.Style.CustomizeFill = true;
cell.Style.BackColor = Color.Red;
cell.Style.DrawFill = true;
MessageBox.Show("Parameters do not match definition inside query, " +
"please check spelling and try again.");
}
private void radGridLedgerAccount_CellFormatting(object sender, CellFormattingEventArgs e)
{
if (e.RowIndex == 0 || e.RowIndex==radGridLedgerAccount.Rows.Count-1)
{
e.CellElement.DrawFill = true;
e.CellElement.ForeColor = Color.White;
e.CellElement.NumberOfColors = 1;
e.CellElement.BackColor = Color.Red;
}
else
{
if (e.CellElement.ColumnInfo.Name == "months") //checking for the text in header cell
{
if (e.RowIndex != 0)
{
System.Drawing.Color col = System.Drawing.ColorTranslator.FromHtml("#6599FF");
e.CellElement.DrawFill = true;
e.CellElement.ForeColor = Color.White;
e.CellElement.NumberOfColors = 1;
e.CellElement.BackColor = col;
}
}
else
{
e.CellElement.DrawFill = true;
e.CellElement.ForeColor = Color.Black;
e.CellElement.NumberOfColors = 1;
e.CellElement.BackColor = Color.White;
e.CellElement.ResetValue(LightVisualElement.ForeColorProperty, ValueResetFlags.Local);
}
}