2011-05-17 18 views

回答

1

這樣的任務通常使用GridView的ShownEditor事件來實現。您應該確定當前重點列和其FieldName(GridView.FocusedColumn.FieldName),然後根據此記錄的另一個單元格中保存的值更改編輯器的DataSource屬性。即

private void gridView1_ShownEditor(object sender, EventArgs e) { 
      GridView gridView = sender as GridView; 
      if(gridView.FocusedColumn.FieldName == "YourField") { 
       CheckedComboBoxEdit edit = gridView.ActiveEditor as CheckedComboBoxEdit; 
       object value = gridView.GetRowCellValue(gridView.FocusedRowHandle, "AnotherColumn"); 
       // filter the datasource and set the editor's DataSource: 
       edit.Properties.DataSource = FilteredDataSource;// your value 
      } 
     } 

此外,請看看How to filter a second LookUp column based on a first LookUp column's value文章,其中類似的任務已解決。

+0

嗨,那麼數據源更改只發生在我想顯示我的字段的編輯器。當我更改「AnotherColumn」的值時,如何清除我的字段中的當前值? – spspli 2011-05-18 13:43:41

+0

這可以使用以下代碼完成:gridView.SetRowCellValue(gridView.FocusedRowHandle,gridView.Columns [「YourField」],null); – 2011-05-18 13:52:32

+0

我在這裏有一個問題:實際上我試圖使用repositoryItemCheckedComboBoxEdit.Items.Clear();我發現我也可以通過這種方式清除我的字段:CheckedComboBoxEdit edit = gridView.ActiveEditor CheckedComboBoxEdit; \t \t \t \t edit.Properties.Items.Clear();在使用這兩種方法時以及何時應使用您提供的方法時,是否有解釋使用方法? – spspli 2011-05-18 15:29:07

0

您可以處理FocusedRowChanged事件,然後根據視圖的GetFocusedRow()設置數據源。

您可能需要具有完整數據源的獨立編輯器才能在未聚焦的列中顯示值,並處理CustomRowCellEditForEditing以在編輯模式下使用子集。

+0

嗨,如果我有另一個column2是一個repositoryItemComboBox,是否有可能根據在repositoryItemComboBox中選擇的值在repositoryItemCheckedComboBoxEdit中填充不同的項目? – spspli 2011-05-17 21:12:17

+0

@sps:是的;按照我剛纔所說的去做。 (或者'GetFocusedRow()'或者調用'GetFocusedRowCellValue()') – SLaks 2011-05-17 21:12:56

+0

嗨有沒有我可以參考的任何示例或類似的東西?我不熟悉這個GetCustomCellEditForEditing – spspli 2011-05-17 21:16:57

相關問題