获取网格列的位置

发布于 2024-07-11 15:28:31 字数 416 浏览 5 评论 0原文

如何在表单中定位按钮,使其始终位于 DevExpress 网格中的列上方?

网格列已设置为无法调整大小,但网格和列会随表单调整大小。 System.Forms.Control 具有 < href="http://msdn.microsoft.com/en-us/library/system.windows.forms.control.pointtoscreen.aspx" rel="nofollow noreferrer">PointToScreen 方法 看起来像吗提供此功能,但不是 DevExpress gridviewcolumn 中的方法。

How can I position a button within a form so that it is always above a column in a DevExpress grid?

The Grid columns are set up so they cannot be resized, but the grid and columns are re-sized with the form. System.Forms.Control has the PointToScreen method that looks like would it provides this functionality, but not a method in a DevExpress gridviewcolumn.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

月下伊人醉 2024-07-18 15:28:31

您可以找到相对于 GridControl 的列坐标,然后将其转换为 Form 坐标。 为此,您可以使用从 GridViewInfo.ColumnsInfo 属性获取的 GridColumnsInfo 对象。 要获取 GridViewInfo 对象,您可以使用 gridView.GetViewInfo() 方法。
找到坐标后,您将需要订阅在不同 GridViewGridControl 更改时发生的事件。 例如,您可以订阅 GridView.Layout 并
GridView.LeftCoordChanged 事件。 要调整大小,您需要订阅 GridControl.Resize 事件。

例子:

private void UpdatePosition(GridView gridView, string columnName, Control control)
{
    var column = gridView.Columns[columnName];

    if (column == null) return;

    var viewInfo = (GridViewInfo)gridView.GetViewInfo(); //using DevExpress.XtraGrid.Views.Grid.ViewInfo
    var columnInfo = viewInfo.ColumnsInfo[column];

    if (columnInfo != null)
    {
        var bounds = columnInfo.Bounds; //column's rectangle of coordinates relative to GridControl

        var point = PointToClient(gridView.GridControl.PointToScreen(bounds.Location)); //translating to form's coordinates

        control.Left = point.X;
        control.Top = point.Y - control.Height;
        control.Width = bounds.Width;

        control.Show();
    }
    else
        control.Hide();
}

您可以为您订阅的每个事件调用此方法。

You can find column coordinates relative to the GridControl and translate then to Form coordinates. For this you can use GridColumnsInfo object that you can get from GridViewInfo.ColumnsInfo property. To get GridViewInfo object you can use gridView.GetViewInfo() method.
Once you find the coordinates, you will need to subscribe to events that occurs at different GridView and GridControl changes. For example you can subscribe to GridView.Layout and
GridView.LeftCoordChanged events. For resizing you need to subscribe to GridControl.Resize event.

Example:

private void UpdatePosition(GridView gridView, string columnName, Control control)
{
    var column = gridView.Columns[columnName];

    if (column == null) return;

    var viewInfo = (GridViewInfo)gridView.GetViewInfo(); //using DevExpress.XtraGrid.Views.Grid.ViewInfo
    var columnInfo = viewInfo.ColumnsInfo[column];

    if (columnInfo != null)
    {
        var bounds = columnInfo.Bounds; //column's rectangle of coordinates relative to GridControl

        var point = PointToClient(gridView.GridControl.PointToScreen(bounds.Location)); //translating to form's coordinates

        control.Left = point.X;
        control.Top = point.Y - control.Height;
        control.Width = bounds.Width;

        control.Show();
    }
    else
        control.Hide();
}

You can call this method for every event that you subscribed.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文