SuperAPI AI 工具集

syncfusion-winforms-record-navigation-control

编程与开发

查看项目

更新于 10-16 01:58

技能介绍

用途

GridRecordNavigationControl 是 Syncfusion 为 Windows Forms 提供的记录导航控件,用于在网格控件中浏览记录。它在网格底部提供类似 Microsoft Access 的导航栏,让用户逐条浏览数据。

适用场景包括:为网格添加记录浏览导航控件;实现类似 Microsoft Access 的记录导航界面;提供首条、末条、上一条、下一条导航功能;在 GridControl 或 GridDataBoundGrid 中导航大型数据集;与 GridGroupingControl 集成导航栏;构建带直观记录浏览的数据驱动应用;向用户显示记录总数与当前位置。

主要能力

  • 内置导航方法:MoveFirst、MoveLast、MoveNext、MovePrevious。
  • 本地化支持:可自定义导航栏文本与标签。
  • 视觉样式:Default、Metro、Office2016 主题。
  • GridGroupingControl 集成:通过 ShowNavigationBar 属性轻松集成。
  • 编程控制:可通过代码动态导航记录。
  • 记录显示:显示当前记录与总记录数。

使用方式

程序集要求

需要引用:Syncfusion.Grid.Windows.dll(核心网格功能与导航控件)、Syncfusion.Shared.Base.dll(共享样式、编辑器与基础组件)。

通过设计器创建(推荐)

  1. 从工具箱将 GridRecordNavigationControl 拖到窗体;
  2. 定位并调整控件大小;
  3. 将 GridDataBoundGrid 拖入 GridRecordNavigationControl 内部;
  4. 设置 GridDataBoundGrid.DataSource 属性。

设计器生成代码示例:

this.recordNavigationControl1 = new Syncfusion.Windows.Forms.Grid.GridRecordNavigationControl();
this.gridDataBoundGrid1 = new Syncfusion.Windows.Forms.Grid.GridDataBoundGrid();

this.recordNavigationControl1.Controls.Add(this.gridDataBoundGrid1);
this.gridDataBoundGrid1.DataSource = myDataSource;

通过代码创建

using Syncfusion.Windows.Forms.Grid;
using System.Drawing;

// Create GridRecordNavigationControl
this.recordNavigationControl1 = new GridRecordNavigationControl();
this.recordNavigationControl1.Location = new Point(32, 48);
this.recordNavigationControl1.Size = new Size(520, 256);
this.recordNavigationControl1.MaxRecord = 1000;
this.recordNavigationControl1.MaxLabel = "of 1000";
this.recordNavigationControl1.NavigationBarWidth = 237;

// Create child grid
this.gridControl1 = new GridControl();
this.gridControl1.RowCount = 1000;
this.gridControl1.ColCount = 16;
this.gridControl1.NumberedRowHeaders = false;

// Add grid to navigation control
this.recordNavigationControl1.Controls.Add(this.gridControl1);

// Add to form
this.Controls.Add(this.recordNavigationControl1);

常见模式

模式 1:数据绑定网格加导航

using Syncfusion.Windows.Forms.Grid;
using System.Data;

// Create navigation control
var navControl = new GridRecordNavigationControl();
navControl.Location = new Point(20, 20);
navControl.Size = new Size(600, 400);

// Create data-bound grid
var dataGrid = new GridDataBoundGrid();
dataGrid.DataSource = GetDataTable(); // Your data source

// Add grid to navigation control
navControl.Controls.Add(dataGrid);

// Configure navigation
navControl.MaxRecord = dataGrid.Model.RowCount;
navControl.MaxLabel = $"of {dataGrid.Model.RowCount}";

this.Controls.Add(navControl);

模式 2:编程导航

private RecordNavigationControl recordNavigationControl;
// Navigate to first record
this.recordNavigationControl.NavigationBar.MoveFirst();

// Navigate to last record
this.recordNavigationControl.NavigationBar.MoveLast();

// Navigate to next record
this.recordNavigationControl.NavigationBar.MoveNext();

// Navigate to previous record
this.recordNavigationControl.NavigationBar.MovePrevious();

模式 3:带样式的导航控件

using Syncfusion.Windows.Forms;

// Apply Metro theme
this.recordNavigationControl1.Style = Appearance.Metro;

// Apply Office2016 theme with Black color scheme
this.recordNavigationControl1.Style = Appearance.Office2016;
this.recordNavigationControl1.GridOfficeScrollBars = OfficeScrollBars.Office2016;
this.recordNavigationControl1.Office2016ScrollBarsColorScheme = 
    ScrollBarOffice2016ColorScheme.Black;

模式 4:GridGroupingControl 加导航

using Syncfusion.Windows.Forms.Grid.Grouping;

// Enable navigation bar on GridGroupingControl
this.gridGroupingControl1.ShowNavigationBar = true;

// Access navigation methods through RecordNavigationBar property
this.gridGroupingControl1.RecordNavigationBar.MoveFirst();
this.gridGroupingControl1.RecordNavigationBar.MoveNext();

关键属性

  • MaxRecord(int):数据集中的记录总数。
  • MaxLabel(string):显示总记录数的标签(如 "of 1000")。
  • NavigationBarWidth(int):导航栏宽度(像素)。
  • SplitBars(DynamicSplitBars):拆分条配置(None、Both、Horizontal、Vertical)。
  • Style(Appearance):视觉样式(Default、Metro、Office2016)。
  • Office2016ScrollBarsColorScheme(ScrollBarOffice2016ColorScheme):Office2016 配色方案。
  • GridOfficeScrollBars(OfficeScrollBars):Office 滚动条样式。
  • ShowNavigationBar(bool,GridGroupingControl):显示/隐藏导航栏。

关键方法

  • MoveFirst():导航到第一条记录。
  • MoveLast():导航到最后一条记录。
  • MoveNext():导航到下一条记录。
  • MovePrevious():导航到上一条记录。

适用场景

  1. 数据库查看器应用:创建数据查看器,让用户像 Microsoft Access 窗体一样逐条浏览数据库记录。
  2. 记录编辑器:构建编辑器界面,用户可在编辑数据时在记录间导航,并清晰显示当前位置。
  3. 大型数据集导航:高效导航 1000 条以上记录,无需一次性加载全部记录到视图。
  4. 分组数据导航:在 GridGroupingControl 中导航分组记录,同时保持分组结构。

实施清单

  • 添加所需程序集引用;
  • 创建 GridRecordNavigationControl(设计器或代码);
  • 添加子网格控件(GridControl 或 GridDataBoundGrid);
  • 配置 MaxRecord 与 MaxLabel 属性;
  • 若使用数据绑定网格,设置数据源;
  • 应用视觉样式/主题(可选);
  • 测试导航方法(首条、末条、下一条、上一条);
  • 处理自定义导航事件(可选)。

最佳实践

  • 设计器优先:使用 Visual Studio 设计器进行初始设置,它会生成正确的初始化代码。
  • 拖放顺序:使用设计器时,先拖放导航控件,再将网格拖入导航控件内部(而非拖到窗体上)。
  • 设置 MaxRecord:始终将 MaxRecord 属性设置为与数据集大小匹配,以保证导航准确。
  • 更新 MaxLabel:保持 MaxLabel 与数据变化同步。
  • 主题一致性:在应用中为所有 Syncfusion 控件应用相同的视觉样式。
  • 程序集引用:使用控件前确认两个必需程序集均已引用。

限制与故障排查

导航不工作:确认子网格已添加到导航控件的 Controls 集合;检查 MaxRecord 设置是否正确;确保网格有数据源或已填充行。

设计器问题:将网格控件拖入导航控件内部,而非拖到窗体上;若控件嵌套不正确,按正确顺序重新创建。

样式未应用:使用 Office2016 样式时确认已设置 Office2016ScrollBarsColorScheme;检查 GridOfficeScrollBars 与 Style 属性是否匹配。

关于收费、价格、平台支持范围等具体信息,资料中暂未提供。