假设使用XtraGrid里面的GridControl控件,名字为GridControl1,里面添加一个GridView1,
现在设计好列,绑定数据库,运行后在GridView1中可以显示出数据库的内容,
问题是,如何动态改变其中一个单元格的属性,例如设计一个按钮,按下就可以改变第2行第2列的单元格背景色、是否只读、等等。
( 只知道设置单元格值的方法是 GridView1.SetRowCellValue("行号","第2列名","新值") ,不知道如何设置属性)想了好几天也没找到办法,求教大家!!
现在设计好列,绑定数据库,运行后在GridView1中可以显示出数据库的内容,
问题是,如何动态改变其中一个单元格的属性,例如设计一个按钮,按下就可以改变第2行第2列的单元格背景色、是否只读、等等。
( 只知道设置单元格值的方法是 GridView1.SetRowCellValue("行号","第2列名","新值") ,不知道如何设置属性)想了好几天也没找到办法,求教大家!!
解决方案 »
- 好心人帮我看看C#语言吧
- c#编程练习题12改良版,正在看回帖的朋友推荐的大话设计模式
- 发个没多大用的东东 使用Alpha混合的WinForm窗体
- 为什么button中的ds没有找到呢??
- 如何使用 windows media player Com组建
- 如何克隆一个ComboBox对象
- 关于数据汇总的问题,请指教.........
- 各位大侠,帮帮忙吧。我的splitter控件动不了,是什么原因啊?
- 如何在窗体程序中调用WORD
- C#开发windows application 窗体间的变量怎么传递???
- 如何遍历Dictionary<int, string>实例?[快速结贴]
- 用C#弄过通视股票驱动接口的朋友请进
DevExpress.XtraGrid.StyleFormatCondition cn;
cn = new DevExpress.XtraGrid.StyleFormatCondition(DevExpress.XtraGrid.FormatConditionEnum.Equal, GridView1.Columns["列名"], null, 0);
cn.Appearance.BackColor = Color.Red;
GridView1.FormatConditions.Add(cn);
cn = new DevExpress.XtraGrid.StyleFormatCondition(DevExpress.XtraGrid.FormatConditionEnum.Equal, GridView1.Columns["列名"], null, 1);
cn.Appearance.BackColor = Color.Green;
GridView1.FormatConditions.Add(cn);这样,这列如果值为0则是红色,为1则是绿色,可我想实现的效果是,在程序中动态直接改变指定位置的单元格的属性(如改变第2行第2列的单元格为只读,可惜GridView1.rows[2][2].ReadOnly=true不能这么用),而且网上关于XtraGrid的用法很少很少,望高手不吝赐教,感激不尽!!!
http://www.devexpress.com/Help/?document=XtraGrid/CustomDocument758.htm
DevExpress.XtraGrid的颜色功能
Category:
在GridView事件中添加以下代码:
Imports DevExpress.XtraGrid.Views.Grid
' ...
Private Sub GridView1_RowStyle(ByVal sender As Object, ByVal e As DevExpress.XtraGrid.Views.Grid.RowStyleEventArgs) Handles GridView1.RowStyle
Dim view As GridView = sender
If (e.RowHandle >= 0) Then
Dim category As String = view.GetRowCellDisplayText(e.RowHandle, view.Columns("Category"))
If category = "Beverages" Then
e.Appearance.BackColor = Color.Salmon
e.Appearance.BackColor2 = Color.SeaShell
End If
End If
End Sub还可以具体选择某几列选择颜色:
Imports DevExpress.XtraGrid.Views.Grid
' ...
Private Sub GridView1_RowCellStyle(ByVal sender As Object, ByVal e As DevExpress.XtraGrid.Views.Grid.RowCellStyleEventArgs) Handles GridView1.RowCellStyle
Dim view As GridView = sender
If e.Column.FieldName = "Count" Or e.Column.FieldName = "Unit Price" Then
Dim category As String = view.GetRowCellDisplayText(e.RowHandle, view.Columns("Category"))
If category = "Seafood" Then
e.Appearance.BackColor = Color.DeepSkyBlue
e.Appearance.BackColor2 = Color.LightCyan
End If
End If
End Sub
对列名为Count和Unit Price的两列显示颜色,其它列不考虑.
(具体详情请查看自带文档中的
ms-help://DevExpress2005/DevExpress.XtraGrid/CustomDocument758.htm) 本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/guyan404/archive/2009/03/19/4005173.aspx
就一个gridControl控件。然后要根据查询的数据不同,把查出的数据填充进去.
之前,确实没有用过它...而且都是English....