Ich habe eine Anforderung, um Daten in Gridview wie folgt zu füllen. Ich habe eine Tabelle, die all diesen Wert speichert. Für jede "Zielspalte" und "Typ" wird ein Wert basierend auf "Quellenspalte" zugewiesen. Aber ich habe ein Problem bei der Einstellung der Vorgabewert für "Zielspalte" und "Typ". Unten ist der Code. Kann mir jemand eine Idee geben? Da bin ich den ganzen Tag dabei geblieben. Jede Hilfe wird sehr geschätzt. Danke im Voraus.C# - Wie Combobox in Datagridview nur in bestimmten Spalte aufzufüllen?
string sqlMatchedData = "SELECT convert(integer, 100 * SIMILARITY) AS SIMILARITY, SOURCE_NAME " +
"FROM TB_LOOKUP_COLUMN WHERE SOURCE_NAME IN (" + allColumnName + ")";
ds = databaseManager.GetData(sqlMatchedData);
//dataGridView1.DataSource = ds.Tables[0];
//dataGridView1.Columns[1].Visible = false;
//dataGridView1.Columns[2].Visible = false;
dt = new DataTable();
DataRow dr;
dt.Columns.Add("Similarity (%)");
dt.Columns.Add("Source Column");
//dt.Columns.Add("C");
//dt.Columns.Add("D");
foreach (DataRow row in ds.Tables[0].Rows)
{
dr = dt.NewRow();
string v = row[0].ToString();
string v1 = row[1].ToString();
//string v2 = row[2].ToString();
//string v3 = row[3].ToString();
dr[0] = v;
dr[1] = v1;
//dr[2] = v2;
//dr[3] = v3;
dt.Rows.Add(dr);
}
dataGridView1.DataSource = dt;
//LookupColumn
string sqlLookupColumn = "SELECT LookUpColumnID, SOURCE_NAME FROM TB_LOOKUP_COLUMN";
DataSet dsColumn = databaseManager.GetData(sqlLookupColumn);
DataGridViewComboBoxColumn comboLookup = new DataGridViewComboBoxColumn();
comboLookup.DataSource = dsColumn.Tables[0];
comboLookup.HeaderText = "Destination Column";
comboLookup.Name = "Destination";
comboLookup.DisplayMember = "SOURCE_NAME";
comboLookup.ValueMember = "LookUpColumnID";
dataGridView1.Columns.Add(comboLookup);
comboLookup.DefaultCellStyle.NullValue = "Please Select";
//datatype
string sqlDataType = "SELECT DataTypeLookUpID, DATATYPE FROM TB_LOOKUP_DATATYPE";
DataSet dsDataType = databaseManager.GetData(sqlDataType);
DataGridViewComboBoxColumn combo = new DataGridViewComboBoxColumn();
combo.DataSource = dsDataType.Tables[0];
combo.HeaderText = "Type";
combo.Name = "Type";
combo.DisplayMember = "DATATYPE";
combo.ValueMember = "DataTypeLookUpID";
dataGridView1.Columns.Add(combo);
combo.DefaultCellStyle.NullValue = "Please Select";
Es tut mir leid, aber das ist in Datagridview nicht Gridview. Zwar gibt es in Datagridview keine rowdatabound, aber ich schaue immer noch auf ähnliche Ereignisse in Datagridview. Danke für die Antwort – MRu