怎么搞定这个?急着用
void RefreshData()
{
string sqlStr;
//DataSet ds = new DataSet();
sqlStr = "select * from ghlb";
ds = SQL.GetDataFromDB(sqlStr);
if (ds != null)
{
dataGridView1.DataSource = ds.Tables[0];
dataGridView1.Columns[1].HeaderText = "号别ID";
dataGridView1.Columns[1].Width = 85;
dataGridView1.Columns[2].HeaderText = "号类";
dataGridView1.Columns[2].Width = 100;
dataGridView1.Columns[3].HeaderText = "科室";
dataGridView1.Columns[3].Width = 100;
dataGridView1.Columns[4].HeaderText = "名称";
dataGridView1.Columns[4].Width = 100;
dataGridView1.Columns[5].HeaderText = "价格";
dataGridView1.Columns[5].Width = 85;
dataGridView1.Columns[6].HeaderText = "简码";
dataGridView1.Columns[6].Width = 100;
dataGridView1.Columns[7].HeaderText = "急诊标记";
dataGridView1.Columns[7].Width = 100;
dataGridView1.Columns[8].HeaderText = "说明";
dataGridView1.Columns[8].Width = 100;
}
else
{
dataGridView1.DataSource = null;
}
}
private void button7_Click(object sender, EventArgs e)
{
try
{
RefreshData();
}
catch (Exception ex)
{
SQL.cn.Close();
MessageBox.Show(ex.Message);
}
}
这个我是想实现全显的功能的,结果,我发现显示在datagridview中的数据错位了。是另外独立的几个列
------解决方案--------------------前台不要绑定,或dataGridView1.Columns[1]改为dataGridView1.Columns['yourcolumname']试下
------解决方案--------------------dataGridView1.AutoGenerateColumns = false;