在gridview c#中获取CheckedListBoxItem devexpress的值 [英] Get the value of CheckedListBoxItem devexpress in gridview c#
问题描述
我在 grivviewDevexpress
中添加了一个 CheckedListBoxItem
,如下所示:
I put a CheckedListBoxItem
in grivviewDevexpress
as you can see here :
我在 page_load $ c $中初始化数据源c>您可以看到:
List<User> confirms = _userRepository.Get().ToList();
ConfirmList.DataSource = confirms;
ConfirmList.DisplayMember = "FullName";
ConfirmList.ValueMember = "Id";
在保存按钮中,用户需要获取所选值(多个选择),但返回null为什么?
In save button I need to get the selected values(more than one selections) by user but it returns null why ?
private void btnSave_ItemClick_1(object sender, ItemClickEventArgs e)
{
gridView.CloseEditor();
Convert.ToDateTime(gridView.GetRowCellValue(rowHandle, "ReturnDateTime"));
CheckedListBoxItem confirms =(CheckedListBoxItem)(gridView.GetRowCellValue(rowHandle, "Confirm"));
}
推荐答案
我可以怀疑你的您要投射的代码 gridView.GetRowCellValue(rowHandle,Confirm)
将值返回为无效类型。通过使用作为
运算符更改下面的代码行。
As i can suspect about your code that you are casting gridView.GetRowCellValue(rowHandle, "Confirm")
returned value to invalid type. Change the below your below line of code by using the as
operator.
CheckedListBoxItem confirms =(CheckedListBoxItem)(gridView.GetRowCellValue(rowHandle, "Confirm"));
至
CheckedListBoxItem confirms = gridView.GetRowCellValue(rowHandle, "Confirm") as CheckedListBoxItem;
if(confirms != null){}
做完之后,你会知道得到什么是调试的结果。
After doing that you will know get what is the result to debug.
正如我可以看到,该编辑器附有列确认
,那么您将从 gridView.GetRowCellValue()
是 Id
属性值用户
类不$ code> CheckedListBoxItem 。
As i can see that editor is attached with the column Confirm
then you will get the result from gridView.GetRowCellValue()
is Id
property value of the User
class not the CheckedListBoxItem
.
当您调用 gridView.CloseEditor();
然后编辑器将不存在以获取CheckedListBoxItem。您可以访问 ColumnView.ShownEditor事件上的编辑器。请参阅以下代码段:
When you call the gridView.CloseEditor();
then editor will not exist to get the CheckedListBoxItem. You can access the editor on the ColumnView.ShownEditor Event. See the below code snippet:
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);
}
}
希望这个帮助..
这篇关于在gridview c#中获取CheckedListBoxItem devexpress的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!