我有一個DGV與如下預先定義的列,這裏是生成方法和結合法數據表到預定義DataGridView列
fixGridAlarm(dgvAlarmlar);
public void fixGridAlarm(DataGridView gvw)
{
gvw.AutoGenerateColumns = false;
gvw.RowTemplate.Height = 75;
gvw.ColumnCount = 3;
gvw.Columns[0].Name = "No";
gvw.Columns[0].Width = 60;
gvw.Columns[0].ReadOnly = true;
gvw.Columns[0].HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter;
gvw.Columns[0].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
gvw.Columns[1].Name = "Tarih/Saat";
gvw.Columns[1].Width = 490;
gvw.Columns[1].ReadOnly = true;
gvw.Columns[1].HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter;
gvw.Columns[1].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
gvw.Columns[2].Name = "Açıklama";
gvw.Columns[2].Width = 1195;
gvw.Columns[2].ReadOnly = true;
gvw.Columns[2].HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter;
gvw.Columns[2].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
BindAlarmlarGrid();
}
public void BindAlarmlarGrid()
{
string CSVFilePathName = pathAlarms;
string[] Lines = File.ReadAllLines(CSVFilePathName);
string[] Fields;
DataTable dt = new DataTable();
dt.Columns.Add(dgvAlarmlar.Columns[0].Name, typeof(int));
dt.Columns.Add(dgvAlarmlar.Columns[1].Name, typeof(DateTime));
dt.Columns.Add(dgvAlarmlar.Columns[2].Name, typeof(string));
DataRow Row;
for (int i = 0; i < Lines.GetLength(0); i++)
{
Fields = Lines[i].Split(new char[] { ',' });
Row = dt.NewRow();
for (int f = 0; f < 3; f++)
{
Row[f] = Fields[f];
}
dt.Rows.Add(Row);
}
dgvAlarmlar.DataSource = dt;
當我給其DataSource
作爲DataTable
列旁邊添加到原始DGV我如何將它綁定在原始網格上而不是下一個?
不要你必須調用'dgvAlarmlar.DataBind();''後= dgvAlarmlar.DataSource DT;' –
它的winform不是asp.net @AlexW – CanESER
即時通訊發現它很難看到什麼問題 –