假设使用XtraGrid里面的GridControl控件,名字为GridControl1,里面添加一个GridView1,
现在设计好列,绑定数据库,运行后在GridView1中可以显示出数据库的内容,
问题是,如何动态改变其中一个单元格的属性,例如设计一个按钮,按下就可以改变第2行第2列的单元格背景色、是否只读、等等。
( 只知道设置单元格值的方法是 GridView1.SetRowCellValue("行号","第2列名","新值") ,不知道如何设置属性)想了好几天也没找到办法,求教大家!!

解决方案 »

  1.   

    现在只知道改变背景色的一种方法:
    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的用法很少很少,望高手不吝赐教,感激不尽!!!
      

  2.   

    处理RowCellStyle,要设置的单元格放到Hashtable里!(还不知道更好的办法)
    http://www.devexpress.com/Help/?document=XtraGrid/CustomDocument758.htm
      

  3.   

    DevExpress.XtraGrid.Views.Grid 的颜色设置 收藏 
    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
      

  4.   

    我从这儿找到的,比着改改就行了http://blog.csdn.net/guyan404/archive/2009/03/19/4005173.aspx
      

  5.   

    需要gridControl动态的改变数据以及列名...不知道怎能做。
    就一个gridControl控件。然后要根据查询的数据不同,把查出的数据填充进去.
    之前,确实没有用过它...而且都是English....