吾爱吃豆豆

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

1、列宽自适应

gv.OptionsView.ColumnAutoWidth = false;

gv.OptionsView.BestFitMode = GridBestFitMode.Fast;

gv.BestFitColumns();

for(int i=0;i<gv.columns.count; i++)

{

gv.columns[i].BestFit();

}

 

2、添加行号并自适应

gv.TopRowChanged += gv_TopRowChanged;

 

private void gridView1_CustomDrawRowIndicator(object sender, DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventArgs e)
{
if (e.Info.IsRowIndicator && e.RowHandle > -1)
{
e.Info.DisplayText = (e.RowHandle + 1).ToString();
}
}

 1 void gv_TopRowChanged(object sender, EventArgs e)
 2 {
 3   GridView view = sender as GridView;
 4     if(view == null) return;
 5     int width = CalcIndicatorDefaultWidth(view);
 6     if((view.IndicatorWidth -4 < width || view.IndicatorWidth +4 >width) && view.IndicatorWidth != width)
 7 {
 8    view.IndicatorWidth =width;
 9 }
10 
11 }

 

posted on 2024-03-18 09:01  吾爱吃豆豆  阅读(790)  评论(0编辑  收藏  举报