日期:2014-05-18 浏览次数:20708 次
int changeId=-1; protected override void OnColumnWidthChanging(ColumnWidthChangingEventArgs e) { if (changeId == -1 || e.ColumnIndex == changeId) { //如果是最后一列,禁止拖动 if (this.Columns[e.ColumnIndex].DisplayIndex == this.Columns.Count - 1) { e.NewWidth = this.Columns[e.ColumnIndex].Width; e.Cancel = true; } else { changeId = e.ColumnIndex; //this.Columns[e.ColumnIndex].Width = e.NewWidth; //e.NewWidth = this.Columns[e.ColumnIndex].Width; //e.Cancel = true; this.Columns[e.ColumnIndex + 1].Width -= (e.NewWidth - this.Columns[e.ColumnIndex].Width); } } base.OnColumnWidthChanging(e); } protected override void OnColumnWidthChanged(ColumnWidthChangedEventArgs e) { if (e.ColumnIndex == changeId) { changeId = -1; } base.OnColumnWidthChanged(e); }