DataGridView使用技巧十:单元格表示值的自定义
生活随笔
收集整理的這篇文章主要介紹了
DataGridView使用技巧十:单元格表示值的自定义
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
通過CellFormatting事件,可以自定義單元格的表示值。(比如:值為Error的時(shí)候,單元格被設(shè)定為紅色)
示例:
1 private void dgv_Users_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e) 2 { 3 try 4 { 5 if (e == null || e.Value == null || !(sender is DataGridView)) 6 return; 7 DataGridView dgv = sender as DataGridView; 8 if (dgv.Columns[e.ColumnIndex].Name=="Sex") 9 { 10 string value = e.Value.ToString(); 11 if (value.Equals("女")) 12 { 13 e.Value = "Woman"; 14 e.FormattingApplied = true; 15 } 16 } 17 } 18 catch (Exception ex) 19 { 20 MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace); 21 } 22 }?
總結(jié)
以上是生活随笔為你收集整理的DataGridView使用技巧十:单元格表示值的自定义的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Redis的数据类型之String
- 下一篇: spring session实现集群中s