GridControl 使用技巧

本文整理了关于Winform中GridControl的一些实用技巧,包括奇行偶行交替变色、显示行号以及数据排序的方法,适用于datagrid类型的控件。
摘要由CSDN通过智能技术生成

以下代码已经有好多人写过,还望各位多多指教

我只不过是整理了一下在我使用过程中的比较熟悉的,在以后的使用过程中会继续添加

1.gridView 奇行与偶行交替变色

this .gridView1.OptionsView.EnableAppearanceEvenRow  =   true ;
this .gridView1.OptionsView.EnableAppearanceOddRow  =   true ;

this .gridView1.Appearance.EvenRow.BackColor  =  System.Drawing.Color.FromArgb((( int )((( byte )( 255 )))), (( int )((( byte )( 255 )))), (( int )((( byte )( 192 )))));
this .gridView1.Appearance.EvenRow.Options.UseBackColor  =   true ;
this .gridView1.Appearance.OddRow.BackColor  =  System.Drawing.Color.FromArgb((( int )((( byte )( 192 )))), (( int )((( byte )( 255 )))), (( int )((( byte )( 255 )))));
this .gridView1.Appearance.OddRow.Options.UseBackColor  =   true ;

2.girdView在第一列显示行号

 

// 调整第一列的宽度
this .gridView1.IndicatorWidth  =   40 ;
// 添加监听事件
this .gridView1.CustomDrawRowIndicator  +=   new  DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventHandler( this .gridView1_CustomDrawRowIndicator);

 

// 在非类里这段代码
private   void  gridView1_CustomDrawRowIndicator( object  sender, DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventArgs e)
        
{
            
if (e.Info.IsRowIndicator && e.RowHandle >= 0)
            
{
                e.Info.DisplayText 
= Convert.ToString(Convert.ToInt32(e.RowHandle.ToString())+1);
            }

        }

 

3.

winform:


gridView1"EndSorting"事件中加入以下代碼:

private   void  gridView1_EndSorting( object  sender, EventArgs e)
        
{
            Color clr 
= gridView1.Appearance.Row.BackColor;
            
foreach (DevExpress.XtraGrid.Columns.GridColumn dc in gridView1.Columns)
            
{
                
if (dc.VisibleIndex == gridView1.SortedColumns[0].VisibleIndex)
                
{
                    dc.AppearanceCell.BackColor 
= Color.Red;
                }

                
else
                
{
                    dc.AppearanceCell.BackColor 
= clr;
                }

           }

       }

 

webfrom:

DataGridSortCommand事件加入以下代碼:
其中dgDataGrid的實例,eSortCommand事件傳入的DataGridSortCommandEventArgs類型參數

foreach (DataGridColumn dgc  in  dg.Columns)
{
 
if (dgc.SortExpression == e.SortExpression)
 
{
  dgc.ItemStyle.BackColor 
= Color.Red;
 }

 
else
 
{
  dgc.ItemStyle.BackColor 
= Color.White;
 }

}

 

4.

去掉GridControl控件上面的
Drag a column header here to group by that column
 
Options/OptionsView/ShowGroupPanel      True----->False
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值