首先需要确认一下gcSpreadSheet1_ActiveSheetChanged方法是否被调用,我的代码如下,可以正常调整行高,你测试一下:
- public partial class MainPage : UserControl
- {
- public MainPage()
- {
- InitializeComponent();
- // 添加 Ctrl + Enter 快捷键输入换行符的功能
- this.gcSpreadSheet1.View.KeyMap.Remove(new GrapeCity.Windows.SpreadSheet.UI.KeyStroke(Key.Enter,ModifierKeys.Control));
- this.gcSpreadSheet1.View.KeyMap.Add(new GrapeCity.Windows.SpreadSheet.UI.KeyStroke(Key.Enter,ModifierKeys.Control),SpreadActions.InputNewLine);
- // 添加 Spread 编辑结束事件,并处理编辑单元格所在行的行高和所在列的列宽
- //this.gcSpreadSheet1.EditEnd += new EventHandler<GrapeCity.Windows.SpreadSheet.UI.EditCellEventArgs>(gcSpreadSheet1_EditEnd);
- this.gcSpreadSheet1.ActiveSheetChanged += new EventHandler(gcSpreadSheet1_ActiveSheetChanged);
- #region 数据源
- List<CItem> list = new List<CItem>();
- list.Add(new CItem(1));
- list.Add(new CItem(2));
- list.Add(new CItem(3));
- list.Add(new CItem(4));
- list.Add(new CItem(5));
- list.Add(new CItem(6));
- list.Add(new CItem(7));
- list.Add(new CItem(8));
- list.Add(new CItem(9));
- list.Add(new CItem(10));
- this.gcSpreadSheet1.SheetCount = 2;
- this.gcSpreadSheet1.Sheets[0].DataSource = list;
- this.gcSpreadSheet1.Sheets[1].DataSource = list;
-
- #endregion
- }
- void gcSpreadSheet1_ActiveSheetChanged(object sender, EventArgs e)
- {
- for (int row = 0; row < this.gcSpreadSheet1.ActiveSheet.Rows.Count; row++)
- {
- this.gcSpreadSheet1.AutoFitRow(row);
- }
- }
- void gcSpreadSheet1_EditEnd(object sender, GrapeCity.Windows.SpreadSheet.UI.EditCellEventArgs e)
- {
- this.gcSpreadSheet1.AutoFitRow(e.Row);
- this.gcSpreadSheet1.AutoFitColumn(e.Column);
- }
- }
- public class CItem
- {
- public CItem(int row)
- {
- Col1 = string.Format("({0},{1})", row, 1);
- Col2 = string.Format("({0},{1})", row, 2);
- Col3 = string.Format("({0},{1})", row, 3);
- Col4 = string.Format("({0},{1})", row, 4);
- Col5 = string.Format("({0},{1})", row, 5);
- Col6 = string.Format("({0},{1})", row, 6);
- Col7 = string.Format("({0},{1})", row, 7);
- }
- public string Col1 { get; set; }
- public string Col2 { get; set; }
- public string Col3 { get; set; }
- public string Col4 { get; set; }
- public string Col5 { get; set; }
- public string Col6 { get; set; }
- public string Col7 { get; set; }
- }
复制代码 |