private void frmSelectStnPart_Load(object sender, EventArgs e) { txt_project.Text = project.FindName(Projectid); txt_site.Text = project.FindSiteName(site); ComboBind(); dataGridView1.Columns.Add("type", "材料类别"); dataGridView1.Columns.Add("partno", "材料编号"); dataGridView1.Columns.Add("partname", "材料规格及名称"); dataGridView1.Columns.Add("typeid", "材料类别id"); dataGridView1.Columns[3].Visible = false; DataSet partDS = StandartPart.FindStnPartDataset(Projectid, site); DataView dv = partDS.Tables[0].DefaultView; int i = 1; foreach (DataRow dr in dv.Table.Rows) { DataGridViewRow r = new DataGridViewRow(); r.CreateCells(dataGridView1); r.Cells[0].Value = PartType.FindPartTypeDesc(Convert.ToInt32(dr[0].ToString())); r.Cells[1].Value = dr[1].ToString(); r.Cells[2].Value = dr[2].ToString(); r.Cells[3].Value = dr[0].ToString(); this.dataGridView1.Rows.Add(r); i++; } //设置列表标题 }
public void GridviewBind(string sql) { this.dataGridView1.AutoGenerateColumns = false; this.dataGridView1.Rows.Clear(); DataSet ds = MEOsub.QueryPartMiscProcList(sql); DataView dv = ds.Tables[0].DefaultView; int i = 1; foreach (DataRow dr in dv.Table.Rows) { DataGridViewRow r = new DataGridViewRow(); r.CreateCells(dataGridView1); r.Cells[0].Value = PartType.FindPartTypeDesc(Convert.ToInt32(dr[0].ToString())); r.Cells[1].Value = dr[1].ToString(); r.Cells[2].Value = dr[2].ToString(); r.Cells[3].Value = dr[0].ToString(); this.dataGridView1.Rows.Add(r); i++; } }