내 DataTable 을 내 DataGridView 에 바인딩해야합니다 . 나는 이것을한다:
DTable = new DataTable();
SBind = new BindingSource();
//ServersTable - DataGridView
for (int i = 0; i < ServersTable.ColumnCount; ++i)
{
DTable.Columns.Add(new DataColumn(ServersTable.Columns[i].Name));
}
for (int i = 0; i < Apps.Count; ++i)
{
DataRow r = DTable.NewRow();
r.BeginEdit();
foreach (DataColumn c in DTable.Columns)
{
r[c.ColumnName] = //writing values
}
r.EndEdit();
DTable.Rows.Add(r);
}
SBind.DataSource = DTable;
ServersTable.DataSource = SBind;
하지만 내가 얻은 것은 DataGridView에 대한 DataTable ADDS NEW 열 뿐입니다 . 나는 이것이 필요하지 않으며, 기존 열 아래에 작성하면됩니다.
이 시도:
ServersTable.Columns.Clear();
ServersTable.DataSource = SBind;
기존 열을 모두 지우지 않으려면 DataPropertyName
다음과 같이 기존 열마다 설정해야합니다 .
for (int i = 0; i < ServersTable.ColumnCount; ++i) {
DTable.Columns.Add(new DataColumn(ServersTable.Columns[i].Name));
ServersTable.Columns[i].DataPropertyName = ServersTable.Columns[i].Name;
}
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다