2017-03-12 53 views
0

我使用的Janus數據網格GridEx和我需要創建自定義細胞: enter image description here詹納斯​​當Gridex:在細胞的自定義用戶控制

我定義數據源,定義類的數組:

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的ToString()實現ILinkPresentationView enter image description here

用戶控件的代碼自動在我的數據網格位於:

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; 
} 

及部分類定義:

public partial class SuspiciousListManagementDialog : BaseForm, ISuspiciousListManagementView 
{ 
    #region ISuspiciousListManagementView 
    public ILinkPresentationView LinkPresentationView { get; set; } 
    public event EventHandler SelectedTypeChanged; 
    public event EventHandler SelectedHistoryTypeChanged; 
    public event EventHandler SelectedShowOnlyActiveChanged; 
    //public event EventHandler Loaded; 

    protected virtual void OnSelectedShowOnlyActiveChanged() 
    { 
     var handler = SelectedShowOnlyActiveChanged; 
     if (handler != null) handler(_showOnlyOneCheckBox.Checked, EventArgs.Empty); 
    } 

    protected virtual void OnSelectedTypeChanged() 
    { 
     var handler = SelectedTypeChanged; 
     if (handler != null) handler(_listTypeComboBox.SelectedValue, EventArgs.Empty); 
    } 
    protected virtual void OnSelectedHistoryTypeChanged() 
    { 
     var handler = SelectedHistoryTypeChanged; 
     if (handler != null) handler(_historyTypeComboBox.SelectedValue, EventArgs.Empty); 
    } 

    //protected virtual void OnLoaded() 
    //{ 
    // var handler = Loaded; 
    // if (handler != null) handler(this, EventArgs.Empty); 
    //} 

    public ICommand BrowseFileCommand { get; set; } 
    public ICommand UploadCommand { get; set; } 
    public ICommand RefreshCommand { get; set; } 

    public new void ShowDialog(System.Windows.Forms.IWin32Window owner) 
    { 
     base.ShowDialog(owner); 
     base.StartPosition = FormStartPosition.CenterParent; 
    } 
    public object AllTypesDataSource 
    { 
     get; 
     set; 
    } 

    private SuspiciousListType _selectedType; 


    public SuspiciousListType SelectedType 
    { 
     get; 
     set; 
    } 

    private string _filePath; 


    public string FilePath 
    { 
     get { return _filePath; } 
     set 
     { 
      _filePath = value; 
      _filePathTextBox.Text = value; 
      ((DelegateCommand)UploadCommand).RaiseCanExecuteChanged(); 
     } 
    } 
    //it is possible. You can create a custom control that inherets from UserControl. Then, set the column type to Text and the EditType to Custom. 

    //You then need to hook up onto the grids InitCustomEdit and EndCustomEdit events where you will perform the custom control logic. 
    private object _historyDataGridSource; 
    public object HistoryDataGridSource 
    { 
     get { return _historyDataGridSource; } 
     set 
     { 
      _historyDataGridSource = value; 

      _dataGrid.DataSource = value; 
      _dataGrid.Refresh(); 
     } 
    } 

    public object AllHistoryAvailableTypesDataSource 
    { 
     get; 
     set; 
    } 

    public SuspiciousFilteredListType SelectedHistoryType 
    { 
     get; 
     set; 
    } 

    public bool ShowOnlyActive 
    { 
     get; 
     set; 
    } 
    #endregion 
    public SuspiciousListManagementDialog() 
    { 
     InitializeComponent(); 
     LinkPresentationView = new LinkPresentationView(); 
     //base.Load += (s, a) => OnLoaded(); 
     base.Load += OnLoad; 
     base.Closed += OnSuspiciousListManagementDialogClosed; 
     //_dataGrid.InitCustomEdit += _dataGrid_InitCustomEdit; 
     //_dataGrid.EndCustomEdit += _dataGrid_EndCustomEdit; 
    } 

    private void grdCookies_InitCustomEdit(object sender, InitCustomEditEventArgs e) 
    { 
     //CheckedComboBox cmb = new CheckedComboBox(); 
     //cmb.VisualStyle = VisualStyle.Office2007; 
     //cmb.ComboStyle = ComboStyle.DropDownList; 
     //cmb.DropDownDataSource = e.Column.Key.Equals(CookiesConstants.COOKIE_HOST) ? _presenter.GetHosts() : _presenter.GetProtocols(); 
     //cmb.DropDownValueMember = CookiesConstants.COOKIE_KEY; 
     //cmb.DropDownDisplayMember = CookiesConstants.COOKIE_KEY; 
     //cmb.DropDownList.ColumnAutoResize = true; 
     //cmb.RetrieveStructure(); 
     //cmb.UncheckAll(); 
     //if (e.Row.RowType == RowType.NewRecord && e.Value != null) 
     //{ 
     // cmb.Text = e.Value.ToString(); 
     //} 
     //else 
     //{ 
     // if (e.Row.Cells[CookiesConstants.COOKIE_ID].Value != null) 
     //  cmb.CheckedItems = _presenter.GetSelectedList((int)e.Row.Cells[CookiesConstants.COOKIE_ID].Value, e.Column.Key.Equals(CookiesConstants.COOKIE_HOST) ? CookiesPresentationPresenter.ListType.Hosts : CookiesPresentationPresenter.ListType.Protocols); 
     //} 
     //cmb.DropDownList.ColumnHeaders = InheritableBoolean.False; 

     //if (e.Column.Key.Equals(CookiesConstants.COOKIE_HOST)) 
     // cmb.Enabled = _presenter.IsHostsListEnabled(e.Row.Cells[CookiesConstants.COOKIE_PROTOCOL].Value); 

     //e.EditControl = cmb; 
    } 

    private void grdCookies_EndCustomEdit(object sender, EndCustomEditEventArgs e) 
    { 
     //CheckedComboBox cmb = e.EditControl as CheckedComboBox; 
     //if (cmb == null) return; 

     //if (e.Column.Key.Equals(CookiesConstants.COOKIE_HOST)) 
     //{ 
     // if (!(string.IsNullOrEmpty(cmb.Text) && e.Row.Cells[CookiesConstants.COOKIE_HOST].Value == null)) 
     // { 
     //  string cellValue = e.Row.Cells[CookiesConstants.COOKIE_HOST].Value == null 
     //        ? string.Empty : e.Row.Cells[CookiesConstants.COOKIE_HOST].Value.ToString().Replace(" ", ""); 

     //  if (!cellValue.Equals(cmb.Text.Replace(" ", ""))) 
     //  { 

     //   e.Row.Cells[CookiesConstants.COOKIE_HOST].Value = cmb.Text; 

     //  } 
     // } 
     //} 
     //else 
     //{ 
     // if (!(string.IsNullOrEmpty(cmb.Text) && e.Row.Cells[CookiesConstants.COOKIE_PROTOCOL].Value == null)) 
     // { 
     //  string cellValue = e.Row.Cells[CookiesConstants.COOKIE_PROTOCOL].Value == null 
     //        ? string.Empty : e.Row.Cells[CookiesConstants.COOKIE_PROTOCOL].Value.ToString().Replace(" ", ""); 

     //  if (!cellValue.Equals(cmb.Text.Replace(" ", ""))) 
     //  { 

     //   e.Row.Cells[CookiesConstants.COOKIE_PROTOCOL].Value = cmb.Text; 

     //   if (_presenter.IsHostsListEnabled(e.Row.Cells[CookiesConstants.COOKIE_PROTOCOL].Value) == false) 
     //   { 
     //    e.Row.Cells[CookiesConstants.COOKIE_HOST].Value = string.Empty; 
     //   } 

     //  } 

     // } 

     //} 


     //if (e.Row.Cells[CookiesConstants.COOKIE_ID].Value != null) 
     // _presenter.SetSelectedList((int)e.Row.Cells[CookiesConstants.COOKIE_ID].Value, 
     //  cmb.CheckedItems, 
     //  e.Column.Key.Equals(CookiesConstants.COOKIE_HOST) ? CookiesPresentationPresenter.ListType.Hosts : CookiesPresentationPresenter.ListType.Protocols); 

    } 


    void OnSuspiciousListManagementDialogClosed(object sender, EventArgs e) 
    { 
     this.FilePath = null; 
     _listTypeComboBox.SelectedItemChanged -= (s, a) => OnSelectedTypeChanged(); 
     _historyTypeComboBox.SelectedItemChanged -= (s, a) => OnSelectedHistoryTypeChanged(); 
     _showOnlyOneCheckBox.CheckStateChanged -= (s, a) => OnSelectedShowOnlyActiveChanged(); 
     UploadCommand.CanExecuteChanged -= OnBrowseFileCommandCanExecuteChanged; 
    } 

    private void OnLoad(object sender, EventArgs e) 
    { 
     _listTypeComboBox.DataSource = AllTypesDataSource; 
     _historyTypeComboBox.DataSource = AllHistoryAvailableTypesDataSource; 

     _listTypeComboBox.SelectedItemChanged += (s, a) => OnSelectedTypeChanged(); 
     _historyTypeComboBox.SelectedItemChanged += (s, a) => OnSelectedHistoryTypeChanged(); 
     _showOnlyOneCheckBox.CheckStateChanged += (s, a) => OnSelectedShowOnlyActiveChanged(); 
     UploadCommand.CanExecuteChanged += OnBrowseFileCommandCanExecuteChanged; 
     _uploadButton.Enabled = UploadCommand.CanExecute(this); 
     _dataGrid.LoadingRow += _dataGrid_LoadingRow; 

     _listTypeComboBox.SelectedIndex = 0; 
     _historyTypeComboBox.SelectedIndex = 0; 

    } 

} 

我不多的想法,所以我會很高興的任何意見或建議。

在此先感謝!

回答

0

據我所知,沒有辦法將自定義控件作爲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); 
    } 

點擊執行通過主持人定義: