I have a DataGridView with to DataSources. One DataSource for one ComboBoxColumn and one for the whole DataGridView.
How can I display the right text for my DataGridViewComboBoxColumn dependig on an ID which is set with the "main" DataSource?
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
After binding all (also the invisible) Columns has the right value. Unless the DataGridViewComboBoxColumn. The value is empty. If I change the colFeinfilter.DataPropertyName = this.ffKennung; to colFeinfilter.DataPropertyName = this.ffnr; then the right ID is displayed. But I need the "ffKennung".