Janus GridEx:单元格中的自定义用户控件

时间:2017-03-12 14:41:01

标签: c# winforms janus gridex

我使用janus数据网格GridEx,我需要创建自定义单元格: enter image description here

我将数据源定义为自定义类的数组:

 public interface ILinkPresentationView
{
    string LinkText { get; set; }
    ICommand LinkCommand { get; set; }
    string LabelText { get; set; }
}
public class SuspiciousListUploadInfoWrapper
{
    private readonly SuspiciousListUploadInfo _model;
    private readonly ILinkPresentationView _linkPresentationView;

    public SuspiciousListUploadInfoWrapper(SuspiciousListUploadInfo model, ILinkPresentationView linkPresentationView)
    {
        if (!Enum.IsDefined(typeof(SuspiciousListType), (int)model.ListType))
            throw new InvalidEnumArgumentException(string.Format("Cannot convert 0 to type 1", model.ListType, typeof(SuspiciousListType)));

        _model = model;
        _linkPresentationView = linkPresentationView;
    }
    public int UploadId
    {
        get { return _model.UploadId; }
    }
    public DateTime UploadTime
    {
        get { return _model.UploadTime; }
    }
    public SuspiciousListType ListType
    {
        get { return (SuspiciousListType)_model.ListType; }
    }
    public string UploadedBy
    {
        get { return _model.UploadedBy; }
    }
    public ILinkPresentationView OriginalFileName
    {
        get { return _linkPresentationView; }
    }
}

其中ILinkPresentationView是用户控件,当前什么都不做,但我打算放置看起来像链接和标签的按钮,显示文件名。但是,如何通过设计器配置我的列并不重要 - 它始终显示实现LinkPresentationView的{​​{1}}的ToString() enter image description here

用户控件的数据网格所在的自动代码:

ILinkPresentationView

及其部分类定义:

partial class SuspiciousListManagementDialog 
{

    /// <summary>
    /// Required designer variable.
    /// </summary>
    private System.ComponentModel.IContainer components = null;

    /// <summary>
    /// Clean up any resources being used.
    /// </summary>
    /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
    protected override void Dispose(bool disposing)
    {
        if (disposing && (components != null))
        {
            components.Dispose();
        }
        base.Dispose(disposing);
    }

    #region Windows Form Designer generated code

    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    private void InitializeComponent()
    {
        Janus.Windows.GridEX.GridEXLayout _dataGrid_DesignTimeLayout = new Janus.Windows.GridEX.GridEXLayout();
        System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(SuspiciousListManagementDialog));
        this._layoutRootSplitContainer = new System.Windows.Forms.SplitContainer();
        this._uploadNewListGroup = new Admin.CustomControl.GenericGroupBox();
        this._uploadButton = new Admin.CustomControl.AdminButton();
        this._browseButton = new Admin.CustomControl.AdminButton();
        this._filePathTextBox = new Admin.CustomControl.AdminTextBox();
        this._filePathLabel = new Admin.CustomControl.AdminLabel();
        this._listTypeLabel = new Admin.CustomControl.AdminLabel();
        this._listTypeComboBox = new Admin.CustomControl.AdminComboBox();
        this._uploadHistory = new Admin.CustomControl.GenericGroupBox();
        this._dataGrid = new SysAdmin.Visual.Generic.AdminGridEX();
        this._refreshButton = new Admin.CustomControl.AdminButton();
        this._showOnlyOneCheckBox = new Admin.CustomControl.AdminCheckBox();
        this._typeLabel = new Admin.CustomControl.AdminLabel();
        this._historyTypeComboBox = new Admin.CustomControl.AdminComboBox();
        ((System.ComponentModel.ISupportInitialize)(this.btnHelp)).BeginInit();
        ((System.ComponentModel.ISupportInitialize)(this.LocalizedFormBasePanel)).BeginInit();
        this.LocalizedFormBasePanel.SuspendLayout();
        ((System.ComponentModel.ISupportInitialize)(this._layoutRootSplitContainer)).BeginInit();
        this._layoutRootSplitContainer.Panel1.SuspendLayout();
        this._layoutRootSplitContainer.Panel2.SuspendLayout();
        this._layoutRootSplitContainer.SuspendLayout();
        ((System.ComponentModel.ISupportInitialize)(this._uploadNewListGroup)).BeginInit();
        this._uploadNewListGroup.SuspendLayout();
        ((System.ComponentModel.ISupportInitialize)(this._uploadHistory)).BeginInit();
        this._uploadHistory.SuspendLayout();
        ((System.ComponentModel.ISupportInitialize)(this._dataGrid)).BeginInit();
        this.SuspendLayout();
        // 
        // btnHelp
        // 
        this.btnHelp.Location = new System.Drawing.Point(994, 2);
        // 
        // LocalizedFormBasePanel
        // 
        this.LocalizedFormBasePanel.Controls.Add(this._layoutRootSplitContainer);
        this.LocalizedFormBasePanel.Size = new System.Drawing.Size(1014, 411);
        this.LocalizedFormBasePanel.Controls.SetChildIndex(this.btnHelp, 0);
        this.LocalizedFormBasePanel.Controls.SetChildIndex(this._layoutRootSplitContainer, 0);
        // 
        // _layoutRootSplitContainer
        // 
        this._layoutRootSplitContainer.Dock = System.Windows.Forms.DockStyle.Fill;
        this._layoutRootSplitContainer.Location = new System.Drawing.Point(0, 0);
        this._layoutRootSplitContainer.Name = "_layoutRootSplitContainer";
        this._layoutRootSplitContainer.Orientation = System.Windows.Forms.Orientation.Horizontal;
        // 
        // _layoutRootSplitContainer.Panel1
        // 
        this._layoutRootSplitContainer.Panel1.Controls.Add(this._uploadNewListGroup);
        // 
        // _layoutRootSplitContainer.Panel2
        // 
        this._layoutRootSplitContainer.Panel2.Controls.Add(this._uploadHistory);
        this._layoutRootSplitContainer.Size = new System.Drawing.Size(1014, 411);
        this._layoutRootSplitContainer.SplitterDistance = 104;
        this._layoutRootSplitContainer.TabIndex = 15;
        // 
        // _uploadNewListGroup
        // 
        this._uploadNewListGroup.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
        this._uploadNewListGroup.Controls.Add(this._uploadButton);
        this._uploadNewListGroup.Controls.Add(this._browseButton);
        this._uploadNewListGroup.Controls.Add(this._filePathTextBox);
        this._uploadNewListGroup.Controls.Add(this._filePathLabel);
        this._uploadNewListGroup.Controls.Add(this._listTypeLabel);
        this._uploadNewListGroup.Controls.Add(this._listTypeComboBox);
        this._uploadNewListGroup.Dock = System.Windows.Forms.DockStyle.Fill;
        this._uploadNewListGroup.GroupBoxHeader = "Upload New List";
        this._uploadNewListGroup.IsAutoVisibilityEnabled = false;
        this._uploadNewListGroup.Location = new System.Drawing.Point(0, 0);
        this._uploadNewListGroup.Margin = new System.Windows.Forms.Padding(5);
        this._uploadNewListGroup.Name = "_uploadNewListGroup";
        this._uploadNewListGroup.Size = new System.Drawing.Size(1014, 104);
        this._uploadNewListGroup.TabIndex = 17;
        this._uploadNewListGroup.Text = "Upload New List";
        // 
        // _uploadButton
        // 
        this._uploadButton.FieldName = null;
        this._uploadButton.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
        this._uploadButton.IsChanged = false;
        this._uploadButton.Location = new System.Drawing.Point(466, 68);
        this._uploadButton.Name = "_uploadButton";
        this._uploadButton.Number = 0;
        this._uploadButton.Size = new System.Drawing.Size(75, 23);
        this._uploadButton.TabIndex = 19;
        this._uploadButton.Text = "Upload";
        this._uploadButton.UseVisualStyleBackColor = false;
        this._uploadButton.Click += new System.EventHandler(this.OnUploadButtonClick);
        // 
        // _browseButton
        // 
        this._browseButton.FieldName = null;
        this._browseButton.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
        this._browseButton.IsChanged = false;
        this._browseButton.Location = new System.Drawing.Point(927, 40);
        this._browseButton.Name = "_browseButton";
        this._browseButton.Number = 0;
        this._browseButton.Size = new System.Drawing.Size(75, 23);
        this._browseButton.TabIndex = 18;
        this._browseButton.Text = "Browse";
        this._browseButton.UseVisualStyleBackColor = false;
        this._browseButton.Click += new System.EventHandler(this.OnBrowseButtonClick);
        // 
        // _filePathTextBox
        // 
        this._filePathTextBox.BackColor = System.Drawing.SystemColors.Control;
        this._filePathTextBox.DefaultValue = null;
        this._filePathTextBox.EnabledField = null;
        this._filePathTextBox.FieldName = null;
        this._filePathTextBox.IsChanged = true;
        this._filePathTextBox.Location = new System.Drawing.Point(79, 42);
        this._filePathTextBox.Name = "_filePathTextBox";
        this._filePathTextBox.ReadOnly = true;
        this._filePathTextBox.Size = new System.Drawing.Size(839, 20);
        this._filePathTextBox.TabIndex = 17;
        this._filePathTextBox.UseSystemPasswordChar = false;
        this._filePathTextBox.ValidityCheck = 0;
        // 
        // _filePathLabel
        // 
        this._filePathLabel.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
        | System.Windows.Forms.AnchorStyles.Right)));
        this._filePathLabel.AutoSize = true;
        this._filePathLabel.FieldName = null;
        this._filePathLabel.IsChanged = false;
        this._filePathLabel.Location = new System.Drawing.Point(6, 47);
        this._filePathLabel.Name = "_filePathLabel";
        this._filePathLabel.Size = new System.Drawing.Size(51, 13);
        this._filePathLabel.TabIndex = 16;
        this._filePathLabel.Text = "File Path:";
        // 
        // _listTypeLabel
        // 
        this._listTypeLabel.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
        | System.Windows.Forms.AnchorStyles.Right)));
        this._listTypeLabel.AutoSize = true;
        this._listTypeLabel.FieldName = null;
        this._listTypeLabel.IsChanged = false;
        this._listTypeLabel.Location = new System.Drawing.Point(6, 20);
        this._listTypeLabel.Name = "_listTypeLabel";
        this._listTypeLabel.Size = new System.Drawing.Size(53, 13);
        this._listTypeLabel.TabIndex = 15;
        this._listTypeLabel.Text = "List Type:";
        // 
        // _listTypeComboBox
        // 
        this._listTypeComboBox.DefaultValue = null;
        this._listTypeComboBox.FieldName = null;
        this._listTypeComboBox.IsChanged = false;
        this._listTypeComboBox.Location = new System.Drawing.Point(79, 16);
        this._listTypeComboBox.Name = "_listTypeComboBox";
        this._listTypeComboBox.Size = new System.Drawing.Size(252, 20);
        this._listTypeComboBox.TabIndex = 14;
        this._listTypeComboBox.Text = "_listTypeComboBox";
        this._listTypeComboBox.ValidityCheck = 0;
        // 
        // _uploadHistory
        // 
        this._uploadHistory.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
        this._uploadHistory.Controls.Add(this._dataGrid);
        this._uploadHistory.Controls.Add(this._refreshButton);
        this._uploadHistory.Controls.Add(this._showOnlyOneCheckBox);
        this._uploadHistory.Controls.Add(this._typeLabel);
        this._uploadHistory.Controls.Add(this._historyTypeComboBox);
        this._uploadHistory.Dock = System.Windows.Forms.DockStyle.Fill;
        this._uploadHistory.GroupBoxHeader = "Upload History";
        this._uploadHistory.IsAutoVisibilityEnabled = false;
        this._uploadHistory.Location = new System.Drawing.Point(0, 0);
        this._uploadHistory.Margin = new System.Windows.Forms.Padding(5);
        this._uploadHistory.Name = "_uploadHistory";
        this._uploadHistory.Size = new System.Drawing.Size(1014, 303);
        this._uploadHistory.TabIndex = 18;
        this._uploadHistory.Text = "Upload History";
        // 
        // _dataGrid
        // 
        this._dataGrid.AllowDelete = Janus.Windows.GridEX.InheritableBoolean.True;
        this._dataGrid.AllowEdit = Janus.Windows.GridEX.InheritableBoolean.False;
        this._dataGrid.ColumnAutoResize = true;
        _dataGrid_DesignTimeLayout.LayoutString = resources.GetString("_dataGrid_DesignTimeLayout.LayoutString");
        this._dataGrid.DesignTimeLayout = _dataGrid_DesignTimeLayout;
        this._dataGrid.Dock = System.Windows.Forms.DockStyle.Bottom;
        this._dataGrid.DynamicFiltering = true;
        this._dataGrid.EnableGridDisabledRows = false;
        this._dataGrid.FilterRowUpdateMode = Janus.Windows.GridEX.FilterRowUpdateMode.WhenValueChanges;
        this._dataGrid.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F);
        this._dataGrid.HideSelection = Janus.Windows.GridEX.HideSelection.HighlightInactive;
        this._dataGrid.Location = new System.Drawing.Point(3, 59);
        this._dataGrid.Margin = new System.Windows.Forms.Padding(2);
        this._dataGrid.Name = "_dataGrid";
        this._dataGrid.Size = new System.Drawing.Size(1008, 241);
        this._dataGrid.TabIndex = 24;
        this._dataGrid.ValidateRowFunc = null;
        this._dataGrid.InitCustomEdit += new Janus.Windows.GridEX.InitCustomEditEventHandler(this.grdCookies_InitCustomEdit);
        this._dataGrid.EndCustomEdit += new Janus.Windows.GridEX.EndCustomEditEventHandler(this.grdCookies_EndCustomEdit);
        // 
        // _refreshButton
        // 
        this._refreshButton.FieldName = null;
        this._refreshButton.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
        this._refreshButton.IsChanged = false;
        this._refreshButton.Location = new System.Drawing.Point(927, 18);
        this._refreshButton.Name = "_refreshButton";
        this._refreshButton.Number = 0;
        this._refreshButton.Size = new System.Drawing.Size(75, 23);
        this._refreshButton.TabIndex = 20;
        this._refreshButton.Text = "Refresh";
        this._refreshButton.UseVisualStyleBackColor = false;
        this._refreshButton.Click += new System.EventHandler(this.OnRefreshButtonClick);
        // 
        // _showOnlyOneCheckBox
        // 
        this._showOnlyOneCheckBox.FieldName = null;
        this._showOnlyOneCheckBox.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
        this._showOnlyOneCheckBox.IsChanged = false;
        this._showOnlyOneCheckBox.Location = new System.Drawing.Point(346, 19);
        this._showOnlyOneCheckBox.Name = "_showOnlyOneCheckBox";
        this._showOnlyOneCheckBox.Size = new System.Drawing.Size(104, 23);
        this._showOnlyOneCheckBox.TabIndex = 23;
        this._showOnlyOneCheckBox.Text = "Show Only Active";
        this._showOnlyOneCheckBox.UseVisualStyleBackColor = false;
        this._showOnlyOneCheckBox.ValidityCheck = 0;
        // 
        // _typeLabel
        // 
        this._typeLabel.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
        | System.Windows.Forms.AnchorStyles.Right)));
        this._typeLabel.AutoSize = true;
        this._typeLabel.FieldName = null;
        this._typeLabel.IsChanged = false;
        this._typeLabel.Location = new System.Drawing.Point(6, 23);
        this._typeLabel.Name = "_typeLabel";
        this._typeLabel.Size = new System.Drawing.Size(53, 13);
        this._typeLabel.TabIndex = 21;
        this._typeLabel.Text = "List Type:";
        // 
        // _historyTypeComboBox
        // 
        this._historyTypeComboBox.DefaultValue = null;
        this._historyTypeComboBox.FieldName = null;
        this._historyTypeComboBox.IsChanged = false;
        this._historyTypeComboBox.Location = new System.Drawing.Point(79, 21);
        this._historyTypeComboBox.Name = "_historyTypeComboBox";
        this._historyTypeComboBox.Size = new System.Drawing.Size(252, 20);
        this._historyTypeComboBox.TabIndex = 20;
        this._historyTypeComboBox.Text = "adminComboBox1";
        this._historyTypeComboBox.ValidityCheck = 0;
        // 
        // SuspiciousListManagementDialog
        // 
        this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
        this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
        this.ClientSize = new System.Drawing.Size(1014, 411);
        this.Name = "SuspiciousListManagementDialog";
        this.Text = "SuspiciousListManagementDialog";
        ((System.ComponentModel.ISupportInitialize)(this.btnHelp)).EndInit();
        ((System.ComponentModel.ISupportInitialize)(this.LocalizedFormBasePanel)).EndInit();
        this.LocalizedFormBasePanel.ResumeLayout(false);
        this._layoutRootSplitContainer.Panel1.ResumeLayout(false);
        this._layoutRootSplitContainer.Panel2.ResumeLayout(false);
        ((System.ComponentModel.ISupportInitialize)(this._layoutRootSplitContainer)).EndInit();
        this._layoutRootSplitContainer.ResumeLayout(false);
        ((System.ComponentModel.ISupportInitialize)(this._uploadNewListGroup)).EndInit();
        this._uploadNewListGroup.ResumeLayout(false);
        this._uploadNewListGroup.PerformLayout();
        ((System.ComponentModel.ISupportInitialize)(this._uploadHistory)).EndInit();
        this._uploadHistory.ResumeLayout(false);
        this._uploadHistory.PerformLayout();
        ((System.ComponentModel.ISupportInitialize)(this._dataGrid)).EndInit();
        this.ResumeLayout(false);

    }

    #endregion

    private System.Windows.Forms.SplitContainer _layoutRootSplitContainer;
    private Admin.CustomControl.GenericGroupBox _uploadNewListGroup;
    private Admin.CustomControl.AdminButton _uploadButton;
    private Admin.CustomControl.AdminButton _browseButton;
    private Admin.CustomControl.AdminTextBox _filePathTextBox;
    private Admin.CustomControl.AdminLabel _filePathLabel;
    private Admin.CustomControl.AdminLabel _listTypeLabel;
    private Admin.CustomControl.AdminComboBox _listTypeComboBox;
    private Admin.CustomControl.GenericGroupBox _uploadHistory;





    private Admin.CustomControl.AdminButton _refreshButton;
    private Admin.CustomControl.AdminCheckBox _showOnlyOneCheckBox;
    private Admin.CustomControl.AdminLabel _typeLabel;
    private Admin.CustomControl.AdminComboBox _historyTypeComboBox;
    private AdminGridEX _dataGrid;
}

我缺乏想法,所以我很乐意接受任何建议或建议。

提前致谢!

1 个答案:

答案 0 :(得分:2)

据我所知,没有办法将自定义控件实现为Janus数据网格的单元格。因此,我提出了我庞大的解决方案: enter image description here 我为链接和文件名定义了单独的列。 点击链接的实施也具有挑战性:

  private void OnLoad(object sender, EventArgs e)
    {
        _listTypeComboBox.DataSource = AllTypesDataSource;          
        _dataGrid.LinkClicked += OnDataGridLinkClicked;
    }

 void OnDataGridLinkClicked(object sender, ColumnActionEventArgs e)
    {
        var dg = (GridEX)sender;
        var wrapper = (SuspiciousListUploadInfoWrapper)dg.CurrentRow.DataRow;
        wrapper.FileOperator.LinkCommand.Execute(wrapper);
    }

点击执行是通过演示者定义的:

相关问题