2016-07-29 6 views
0

cのGridViewの中CheckedListBoxItemのDevExpress社の値を取得します私は<code>grivviewDevexpress</code>で<code>CheckedListBoxItem</code>を置く#

List<User> confirms = _userRepository.Get().ToList(); 
      ConfirmList.DataSource = confirms; 
      ConfirmList.DisplayMember = "FullName"; 
      ConfirmList.ValueMember = "Id"; 

保存ボタンでは、ユーザーが選択した値(複数の選択肢)を取得する必要がありますが、なぜnullを返しますか?

private void btnSave_ItemClick_1(object sender, ItemClickEventArgs e) 
{ 
    gridView.CloseEditor(); 
    Convert.ToDateTime(gridView.GetRowCellValue(rowHandle, "ReturnDateTime")); 
    CheckedListBoxItem confirms =(CheckedListBoxItem)(gridView.GetRowCellValue(rowHandle, "Confirm")); 
} 
+0

あなたが「確認」欄に何を保存しますか?私はリストのデータソースから見ることができます。 UserのIdプロパティと同様のデータ型を持つ必要があります。 –

+0

@NiranjanKalaどういう意味ですか?私は鋳造する必要がある質問 –

答えて

0

あなたのコードが無効な型に戻り値gridView.GetRowCellValue(rowHandle, "Confirm")をキャストしていると思われることがあります。 as演算子を使用して、以下のコード行を変更します。

CheckedListBoxItem confirms = gridView.GetRowCellValue(rowHandle, "Confirm") as CheckedListBoxItem; 
if(confirms != null){} 

CheckedListBoxItem confirms =(CheckedListBoxItem)(gridView.GetRowCellValue(rowHandle, "Confirm")); 

デバッグに結果であるものを得る知っているだろうことを行った後。

私はそのエディタは、あなたがgridView.GetRowCellValue()から結果を取得する列Confirmが装着されて見ることができるように

Userクラスではない CheckedListBoxItemIdプロパティ値です。

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

・ホープ、このヘルプ..

+0

あなたのコードをありがとうが、それは再びnull nullを返します –

+0

あなたのソリューションは、あなたが選択後にグリッドセルからキーを取得する私の提案に似ています。これらのキーを使用して、データソースから実際のレコードをフェッチすることができます。リストで複数選択が可能な場合、質問は質問テキストとは関係ありません。誰もあなたがリストから複数の値を取得したいと判断することはできません。あなたが問題を解決したことは素晴らしいことです –

-1

キャスティングタイプが問題だと思います。

+0

について説明しましたか? –

関連する問題

 関連する問題