正如我可以懷疑你的代碼,你正在鑄造gridView.GetRowCellValue(rowHandle, "Confirm")
返回值爲無效類型。使用as
運算符更改以下代碼行。
CheckedListBoxItem confirms =(CheckedListBoxItem)(gridView.GetRowCellValue(rowHandle, "Confirm"));
到
CheckedListBoxItem confirms = gridView.GetRowCellValue(rowHandle, "Confirm") as CheckedListBoxItem;
if(confirms != null){}
這樣做,你就會知道得到的結果是什麼調試後。
,我可以看到編輯器上安裝有列Confirm
那麼你會從gridView.GetRowCellValue()
得到的結果是User
類不是CheckedListBoxItem
的Id
屬性值。
當您調用gridView.CloseEditor();
時,編輯器將不存在以獲取CheckedListBoxItem。您可以訪問ColumnView.ShownEditor Event上的編輯器。請參見下面的代碼片段:
private void MainForm_Load(object sender, EventArgs e) {
this.PhonesSource.DataSource = DataContext.GetPhones();
this.CountriesSource.DataSource = DataContext.GetCountries();
this.CitiesSource.DataSource = DataContext.GetAllCities();
}
private void GridView_ShownEditor(object sender, EventArgs e) {
ColumnView view = (ColumnView)sender;
if (view.FocusedColumn.FieldName == "CityCode") {
LookUpEdit editor = (LookUpEdit)view.ActiveEditor;
string countryCode = Convert.ToString(view.GetFocusedRowCellValue("CountryCode"));
editor.Properties.DataSource = DataContext.GetCitiesByCountryCode(countryCode);
}
}
// In certain scenarios you may want to clear the secondary editor's value
// You can use the RepositoryItem.EditValueChanged event for this purpose
private void CountryEditor_EditValueChanged(object sender, EventArgs e) {
this.GridView.PostEditor();
this.GridView.SetFocusedRowCellValue("CityCode", null);
}
private void MainForm_Load(object sender, EventArgs e) {
this.PhonesSource.DataSource = DataContext.GetPhones();
this.CountriesSource.DataSource = DataContext.GetCountries();
this.CitiesSource.DataSource = DataContext.GetAllCities();
}
private void GridView_ShownEditor(object sender, EventArgs e) {
ColumnView view = (ColumnView)sender;
if (view.FocusedColumn.FieldName == "CityCode") {
LookUpEdit editor = (LookUpEdit)view.ActiveEditor;
string countryCode = Convert.ToString(view.GetFocusedRowCellValue("CountryCode"));
editor.Properties.DataSource = DataContext.GetCitiesByCountryCode(countryCode);
}
}
希望這有助於..
你怎麼在「確認」欄中存儲?正如我可以從列表的數據源中看到的那樣。它應該具有與User的Id屬性類似的數據類型。 –
@NiranjanKala這是什麼意思?我在問題 –