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 }
标签:gv,gridview,适应,width,宽度,IndicatorWidth,TopRowChanged,view From: https://www.cnblogs.com/hebdzw/p/18079604