首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >SSMS中的网格控制

SSMS中的网格控制
EN

Stack Overflow用户
提问于 2017-06-05 02:16:15
回答 1查看 2.1K关注 0票数 14

我注意到在SSMS ( 2016)中,查询结果在一秒内返回( 10k+行上方)。结果表/网格滚动非常平滑,在SSMS上内存占用极低(~80 an )。这种类似网格/视图的控制方式可以执行ListView (~200 10,2-3秒)和DataGrid (~600 10,8-10秒)。即使我关闭所有可视化或调整取消滚动或修复它的高度来优化速度,它们仍然在SSMS中远远落后于网格,仍然具有缓慢的滚动和GUI操作。

在SSMS中使用的网格控件背后是什么使它变得如此平滑?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-07-07 13:53:14

SSMS网格不是C++,它不是ListView,也不是DataGrid,它不使用Windows本机控件,它“只是”一个自定义.NET控件,名为GridControl (在Microsoft.SqlServer.Management.UI.Grid命名空间中),属于名为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文件中等等。

它不是一个可再发行的二进制AFAIK,所以你不应该发布它,它没有文档,它也不是一个功能齐全的网格。然而,正如您所发现的,它是轻量级的,它可以是快速的,与底层数据访问一样快。

如果您想玩它,下面是一个小型Winforms C#示例(一个10000×256个网格,即立即打开的25亿个单元格),演示如何使用它:

代码语言:javascript
复制
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();
    }
}

这是看上去的样子。你可以在一台像样的电脑上滚动而不减速。

票数 23
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44360824

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档