2016-08-04 12 views
0

Ich habe eine DataGridView mit DataSources. Eine DataSource für eine ComboBoxColumn und eine für die gesamte DataGridView.Set DataGridViewComboBoxColumn.ValueMember zu einer anderen Spalte

Wie kann ich den richtigen Text für meine DataGridViewComboBoxColumn anzeigen, abhängig von einer ID, die mit der DataSource "main" festgelegt wurde?

this.dgvFeinfilter.AutoGenerateColumns = false; 
this.dgvFeinfilter.SelectionMode = DataGridViewSelectionMode.RowHeaderSelect; 

DataGridViewTextBoxColumn colFFZNr = new DataGridViewTextBoxColumn(); 
colFFZNr.Name = this.ffznr; 
colFFZNr.DataPropertyName = this.ffznr; 
colFFZNr.Visible = false; 

DataGridViewTextBoxColumn colFFFnr = new DataGridViewTextBoxColumn(); 
colFFFnr.Name = this.fffnr; 
colFFFnr.DataPropertyName = this.fffnr; 
colFFFnr.Visible = false; 

DataGridViewTextBoxColumn colFFnr = new DataGridViewTextBoxColumn(); 
colFFnr.Name = this.ffnr; 
colFFnr.DataPropertyName = this.ffnr; 
colFFnr.Visible = false; 

DataGridViewTextBoxColumn colFFPosition = new DataGridViewTextBoxColumn(); 
colFFPosition.Name = this.ffPosition; 
colFFPosition.HeaderText = this.headerReihenfolge; 
colFFPosition.DataPropertyName = this.ffPosition; 
colFFPosition.Visible = true; 

DataGridViewComboBoxColumn colFeinfilter = new DataGridViewComboBoxColumn(); 
colFeinfilter.DataSource = this.DsView.Tables["Feinfilter"]; 
colFeinfilter.DropDownStyle = ComboBoxStyle.DropDownList; 
colFeinfilter.HeaderText = this.headerFeinfilter; 
colFeinfilter.DataPropertyName = this.ffKennung; //this.ffnr; 
colFeinfilter.DisplayMember = this.ffKennung; 
colFeinfilter.ValueMember = this.ffnr; 
colFeinfilter.Name = this.ffKennung; 
colFeinfilter.Width = 300; 

DataGridViewTextBoxColumn colDelete = new DataGridViewTextBoxColumn(); 
colDelete.Name = "MarkForDelete"; 
colDelete.Visible = false; 
colDelete.DefaultCellStyle.NullValue = 0; 

EnumerableRowCollection<DataRow> query = from zuordnung in this.DsWork.Tables["FFZuordnung"].AsEnumerable() 
             where zuordnung.Field<Decimal>(this.fffnr) == this.feinfilterfolge.FFFNr 
             select zuordnung; 

DataView newView = query.AsDataView(); 
this.dgvFeinfilter.DataSource = newView; 
this.dgvFeinfilter.Columns.AddRange(colFFPosition, colFeinfilter, colFFZNr, colFFFnr, colFFnr, colDelete); 

Datasource-1 (this.DsView.Tables [ "Feinfilter"]):

SELECT 
    FFSPNR, -- id 
    FFKENNUNG -- name 
FROM 
    Feinfilter 
WHERE 
    FFKENNUNG IS NOT NULL 

Datasource-2 (this.DsWork.Tables [ "FFZuordnung"]):

SELECT 
    FFZLFDNR,  --id 
    FFSPNR,   --fk 
    FFFNr,   --fk 
    FFZREIHENFOLGE, --number 
    TSUPDATE   --datetime 
FROM 
    FFZUORDNUNG 

Nach dem Binden haben alle (auch die unsichtbaren) Spalten den richtigen Wert. Es sei denn die DataGridViewComboBoxColumn. Der Wert ist leer. Wenn ich die colFeinfilter.DataPropertyName = this.ffKennung; zu colFeinfilter.DataPropertyName = this.ffnr; ändere, wird die richtige ID angezeigt. Aber ich brauche die "ffKennung".

Antwort

0

Sie benötigen

colFeinfilter.DataPropertyName = this.ffnr; 
colFeinfilter.DisplayMember = this.ffKennung; 

Wert von DataPropertyName gesetzt wird definiert, welcher Wert muss
Wert von DisplayMember ausgewählt werden verwendet werden, um Text anzuzeigen für ausgewählte Wert

+0

leider nicht dieses Werk hier. – Bambuk

Verwandte Themen