c# - DataTable to Pre Defined DataGridView Columns -
i have dgv pre defined columns below , here generation method , binding method
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; (int = 0; < lines.getlength(0); i++) { fields = lines[i].split(new char[] { ',' }); row = dt.newrow(); (int f = 0; f < 3; f++) { row[f] = fields[f]; } dt.rows.add(row); } dgvalarmlar.datasource = dt;
when give datasource
datatable
columns added next original dgv how can bind on original grid instead of next?
i solved problem changing binding method instead of using datatable
public void bindalarmlargrid() { string csvfilepathname = pathalarms; string[] lines = file.readalllines(csvfilepathname); string[] fields; (int = 0; < lines.getlength(0); i++) { fields = lines[i].split(new char[] { ',' }); dgvalarmlar.rows.add(fields); } }
Comments
Post a Comment