2014-06-14 1 views
0

내가 데이터 바인딩을하려고 안녕하세요, 내가 DataGrid에 바인딩 보이는 보려는 Form1 클래스의 객체의 목록을 가지고 같은 :데이터 바인딩 된 DataGridView comboboxcolumn 및 텍스트 상자

public partial class Form1 : Form 
{ 

    public BindingList<PrefixDataAffichable> prefixepresent { get; set; } 

    public Form1() 
    { 
     InitializeComponent(); 
     prefixepresent = new BindingList<PrefixDataAffichable>(); 
     LoadData(); 
     dataGridView1.DataSource = prefixepresent; 
    } 


} 

과 PrefixDataAffichable 클래스 외모 같은

public class PrefixDataAffichable 
{ 
    public string PrfixeInstance { get; set; } 
    public BindingList<string> PrfixePossibleChoice { get; set; } 
    public string PrefixeDescription { get; set; } 

    BindingList<string> PrfixePoPrfixeInstancessibleChoice = new BindingList<string>(); 

    public PrefixDataAffichable(PrefixRef prefixref) 
    { 
     PrefixeDescription = prefixref.prefix._description; 
     PrfixeInstance = prefixref.prefix._prefixe + "(" + prefixref.texteentreparanthese + ")"; 
     PrfixePossibleChoice.Add(_PrfixeInstance); 
     PrfixePossibleChoice.Add(_PrfixeInstance + "1!"); 

    } 

} 

때 수행하여 2 열 textboxcolumn으로 표시하지만 난 콤보 상자 열 apppear 할 수없는 데이터 바인딩. 나는 그것을 수동으로 생성하고 DataPropertyName manully를 다음과 같이 설정하는 것에 지쳤다. PrfixePossibleChoice 그러나 프로그램이 실행될 때 프로그램은 크래킹한다.

데이터 바인딩 소스로 클래스를 선택하거나 코드별로 열을 추가 할 때 열을 표시하는 방법을 알고 있어야합니다.

업데이트 : 나는 코드

dataGridView1.DataSource = prefixepresent; 
DataGridViewComboBoxColumn colbox = new DataGridViewComboBoxColumn(); 
colbox.DataPropertyName = "PrfixePossibleChoice"; 
dataGridView1.Columns.Add(colbox); 

추가 오류가 있습니다 : System.ArgumentException : DataGridViewComboBoxCell 값이 유효하지 않습니다.

+0

어떤 오류가 발생합니까? DataPropertyName을 사용하여 콤보 상자 열을 수동으로 바인드하려고 시도한 방법 (우체국 코드) – Junaith

+0

@Junaith 질문이 업데이트되었습니다.이 질문이 명확하고 사용자가 나를 도울 수 있기를 바랍니다. – user3704628

답변

0

콤보 박스를 바인딩하는 동안 콤보 박스 열에 대해 DataSource을 설정해야합니다. 콤보 상자 열의 DataSource 또는 Items 컬렉션에서 콤보 상자 셀에 설정된 값을 사용할 수 없기 때문에 오류가 발생합니다.

dataGridView1.DataSource = prefixepresent; 
DataGridViewComboBoxColumn colbox = new DataGridViewComboBoxColumn(); 
colbox.DataPropertyName = "PrfixePossibleChoice"; 
colbox.DataSource = set the datasource here 
dataGridView1.Columns.Add(colbox); 
관련 문제