Get the App
SLTechnology News&Howtos  ›  Development  › 

How to change BackColor in EditForm

Shulou Source: shulou.com Published: 2022-06-03 06:35:57 10月14日 Update

This article introduces the knowledge about "how to change BackColor in EditForm". In the actual case operation process, many people will encounter such difficulties. Next, let Xiaobian lead you to learn how to deal with these situations! I hope you can read carefully and learn something!

problem

Suppose you dynamically change the color of RowCell in GridView:

C#

private void GridView_RowCellStyle(object sender, RowCellStyleEventArgs e){// ... some logice.Appearance.BackColor = Color.FromArgb(98, 182, 204, 252);// ... other logic}

You need to use the same BackColor in the corresponding edit form control. It is necessary to use the EditFormPrepared event and change the e.BindableControls [column] .BackColor property, but I want to know how to get column styles.

solutions

The task is to get the colors of the corresponding column cells, and it is recommended that you create a method that implements RowCellStyle logic to calculate cell colors and use them in the EditFormPrepared event handler. The following code illustrates this method:

C#

private void GridView1_EditFormPrepared(object sender, EditFormPreparedEventArgs e) {GridView view = sender as GridView;foreach (GridColumn c in view.VisibleColumns) {e.BindableControls[c].BackColor = GetColor(c, e.RowHandle, view.GetRowCellValue(e.RowHandle, c));}}private void GridView1_RowCellStyle(object sender, RowCellStyleEventArgs e) { e.Appearance.BackColor = GetColor(e.Column, e.RowHandle, e.CellValue); }Color GetColor(GridColumn column, int rowHandle, object value) {if (rowHandle != 0)return Color.Empty;//your logicif (column.FieldName == "Name")return Color.Green;return Color.Red;}"How to change BackColor in EditForm" is introduced here. Thank you for reading. If you want to know more about industry-related knowledge, you can pay attention to the website. Xiaobian will output more high-quality practical articles for everyone!

Tags: Color event content unit method more knowledge practical same necessary learned next code task dynamic dilemma actual attribute suggestion situation Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info NVidia Apple Xiaomi macOS