Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to change BackColor in EditForm

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 266

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report