.NET TIPS: DataGrid is set in the color of the value of a column

xiaoxiao2021-03-06  68

Today, it is true, and it is a halo steering in the interface. In order to achieve a line of the .NET WINDOW DATAGRID, you can set the function of the row in accordance with the contents of the value of the row. First, there is a connection, there is a lot of DataGrid's function expansion Solution Windows Forms DataGrid has no solution to this demand, and finally finally got it under the help of colleagues. It is not posted by setting the color of the cell by a cell value. There is a solution. Below is a solution to the colors of the value of a column. The key is to add a DataView property in the custom DataGridTextBoxColumn, which is overloaded ().? When using DataGridTextBoxColumn, ? DataGrid bound DataView assigned to it .public class public class DataGridColoredTextBoxColumn: DataGridTextBoxColumn {???? private System.Data.DataView m_bindDataView; ??? public DataView BindingDataView ??? {?????????? ? GET ??????? {???????????? Return m_binddataview; ???????} ??????? {? ?????????? m_binddataview = value; ????} ??} ?? protected override void paint (system.drawing.graphchics g, ??? system.drawing.Rectangle Bounds, System.Windows. Forms.CurrencyManager ??? source, int rowNum, System.Drawing.Brush backBrush, System.Drawing.Brush ??? foreBrush, bool alignToRight) ?? {????? // the idea is to conditionally set the foreBrush and / or backbrush ????? // depending Upon Some CriRia on the Cell V Alue ????? // Here, We Color Anything That Begins with a letter higher Than 'f' ????? try ????? {??????????? // from DataView Take the value, "itemtype" is the name of the line ???????????? String colvalue = this.bindingDataView [rownum] ["itemtype"]. TOSTRING (); ???????? ??????? char val = colvalue [0]; ???????????? IF (Val> 'f') // If the first letter is greater than 'f' ??????? ???? {???????????????? backbrush = new solidbrush (color.blueviolet); ???????????????? forebrush = new Solidbrush (color.white);

转载请注明原文地址:https://www.9cbs.com/read-120211.html

New Post(0)