SSMS 网格不是 C++,它不是 ListView 也不是 DataGrid,它不使用 Windows 原生控件,它“只是”一个名为 GridControl(在 Microsoft.SqlServer.Management.UI.Grid 命名空间中)的自定义 .NET 控件,属于名为 Microsoft.SqlServer.GridControl.dll 的程序集。
您可以在不同的地方找到它:GAC、%ProgramFiles(x86)%\Common Files\Microsoft Shared\SQL Server Developer Tools、%ProgramFiles(x86)%\Microsoft SQL Server Management Studio 18\Common7\IDE、Visual Studio 文件等。
它不是一个可再发行的二进制 AFAIK,所以你不应该发布它,它没有文档记录,也不是像其他的全功能网格。但是,正如您所发现的,它是轻量级的,而且速度很快,与您的底层数据访问一样快。
如果您想使用它,这里有一个小的 Winforms C# 示例(一个 10000 x 256 网格,即立即打开的 250 万个单元格)演示如何使用它:
using System;
using System.Drawing;
using System.Windows.Forms;
using Microsoft.SqlServer.Management.UI.Grid;
namespace WindowsFormsApp1
{
public partial class Form1 : Form
{
private GridControl _control = new GridControl();
public Form1()
{
InitializeComponent();
for (int i = 0; i < 256; i++)
{
_control.AddColumn(new GridColumnInfo { HeaderType = GridColumnHeaderType.Text, IsUserResizable = true });
_control.SetHeaderInfo(i, "Column " + i, null);
}
_control.Dock = DockStyle.Fill;
_control.GridStorage = new GridStorage();
Controls.Add(_control);
}
}
// represents a datasource
public class GridStorage : IGridStorage
{
public long EnsureRowsInBuf(long FirstRowIndex, long LastRowIndex)
{
return NumRows(); // pagination, dynamic load, virtualization, could happen here
}
public void FillControlWithData(long nRowIndex, int nColIndex, IGridEmbeddedControl control)
{
// for cell edition
control.SetCurSelectionAsString(GetCellDataAsString(nRowIndex, nColIndex));
}
public string GetCellDataAsString(long nRowIndex, int nColIndex)
{
// get cell data
return nRowIndex + " x " + nColIndex;
}
public int IsCellEditable(long nRowIndex, int nColIndex)
{
return 1; // 1 means yes, 0 means false
}
public long NumRows()
{
return 10000;
}
public bool SetCellDataFromControl(long nRowIndex, int nColIndex, IGridEmbeddedControl control)
{
// when a cell has changed, you're supposed to change your data here
return true;
}
public Bitmap GetCellDataAsBitmap(long nRowIndex, int nColIndex) => throw new NotImplementedException();
public void GetCellDataForButton(long nRowIndex, int nColIndex, out ButtonCellState state, out Bitmap image, out string buttonLabel) => throw new NotImplementedException();
public GridCheckBoxState GetCellDataForCheckBox(long nRowIndex, int nColIndex) => throw new NotImplementedException();
}
}
这就是它的样子。您可以在一台不错的计算机上滚动而不会减慢速度。