本文介绍了在gridview c#中获取CheckedListBoxItem devexpress的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我在 grivviewDevexpress 中添加了一个 CheckedListBoxItem ,如下所示:

I put a CheckedListBoxItem in grivviewDevexpress as you can see here :

我在 page_load 您可以看到:

 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。您可以访问上的编辑器。请参阅以下代码段:

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的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-08 23:16