2024年终活动

DevExpress控件使用交流,DevExpress中国社区Dev联系电话 联系电话:023-68661681

如何创建一个支持垂直导航的自定义GridControl?

来源:本站原创   发布时间:2012-11-05   浏览:2829次

问题描述:如何创建一个支持垂直导航的自定义GridControl?

解决方法:

C#

using System;
using System.Collections.Generic;
using System.Linq;
using DevExpress.XtraGrid;
using DevExpress.XtraEditors;
using DevExpress.XtraGrid.Views.Base;
using DevExpress.XtraGrid.Registrator;
using VerticalDataNavigator.Navigator;

namespace VerticalDataNavigator
{

    [System.ComponentModel.DesignerCategory("")]
    public class CustomGridControl : GridControl
    {


        protected override ControlNavigator CreateEmbeddedNavigator()
        {
            ExtendedDataNavigator nav = new ExtendedDataNavigator(this);
            nav.SizeChanged += OnEmbeddedNavigator_SizeChanged;
            return nav;
        }


        protected override void RegisterAvailableViewsCore(InfoCollection collection)
        {
            base.RegisterAvailableViewsCore(collection);
            collection.Add(new CustomGridViewInfoRegistrator());
        }


        public NavigatorOrientation EmbeddedNavigatorOrientation
        {
            get { return (EmbeddedNavigator as ExtendedDataNavigator).NavigatorOrientation; }
            set
            {
                ExtendedDataNavigator customizableNavigator = EmbeddedNavigator as ExtendedDataNavigator;


                if (value != customizableNavigator.NavigatorOrientation)
                {
                    customizableNavigator.NavigatorOrientation = value;
                    Invalidate();
                }
            }
        }
    }
}

VB.NET

Imports Microsoft.VisualBasic
Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports DevExpress.XtraGrid
Imports DevExpress.XtraEditors
Imports DevExpress.XtraGrid.Views.Base
Imports DevExpress.XtraGrid.Registrator
Imports VerticalDataNavigator.Navigator
Namespace VerticalDataNavigator
    <System.ComponentModel.DesignerCategory("")> _
    Public Class CustomGridControl
        Inherits GridControl
        Protected Overrides Function CreateEmbeddedNavigator() As ControlNavigator
            Dim nav As New ExtendedDataNavigator(Me)
            AddHandler nav.SizeChanged, AddressOf OnEmbeddedNavigator_SizeChanged
            Return nav
        End Function
        Protected Overrides Sub RegisterAvailableViewsCore(ByVal collection As InfoCollection)
            MyBase.RegisterAvailableViewsCore(collection)
            collection.Add(New CustomGridViewInfoRegistrator())
        End Sub
        Public Property EmbeddedNavigatorOrientation() As NavigatorOrientation
            Get
                Return (TryCast(EmbeddedNavigator, ExtendedDataNavigator)).NavigatorOrientation
            End Get
            Set(ByVal value As NavigatorOrientation)
                Dim customizableNavigator As ExtendedDataNavigator = TryCast(EmbeddedNavigator, ExtendedDataNavigator)
                If value <> customizableNavigator.NavigatorOrientation Then
                    customizableNavigator.NavigatorOrientation = value
                    Invalidate()
                End If
            End Set
        End Property
    End Class
End Namespace

本站文章除注明转载外,均为本站原创或翻译
欢迎任何形式的转载,但请务必注明出处,尊重他人劳动成果
转载请注明:文章转载自:DevExpress控件中文网 [https://www.devexpresscn.com/]
本文地址:https://www.devexpresscn.com/post/405.html
扫码咨询
电话咨询
023-68661681
返回
顶部