如何更改DatagridView列标题?

时间:2013-12-19 13:04:42

标签: c# sql winforms datagridview

string strConnection = ConfigurationManager.ConnectionStrings["Harfosh.Properties.Settings.TYT"].ConnectionString;

//string strConnection = "ConfigurationManager.ConnectionStrings[Store_Manager.Properties.Settings.storemanagerConnectionString].Name;";
SqlConnection con = new SqlConnection(strConnection);
con.Open();
SqlCommand sqlCmd = new SqlCommand();
sqlCmd.Connection = con;
sqlCmd.CommandType = CommandType.Text;
sqlCmd.CommandText = "Select rakmsanf ,esmsanf,esmmwrd,m5zn,quantity,w7da,reorder from Items  Where m5zn =N'" + comboBox2.Text + "' ";
SqlDataAdapter sqlDataAdap = new SqlDataAdapter(sqlCmd);
System.Data.DataTable dtRecord = new System.Data.DataTable();
sqlDataAdap.Fill(dtRecord);
//  DataGridView dataGridView1 = new DataGridView();


dataGridView1.DataSource = dtRecord;

if (dataGridView1.Columns[0] != null)
    dataGridView1.Columns[0].HeaderText = "Key";
if (dataGridView1.Columns[1] != null)
    dataGridView1.Columns[1].HeaderText = "Expire";
con.Close();

现在我得到rakmsanf,esmsanf,esmmwrd,m5zn,quantity,w7da,reorder AND key Expire
我想将列标题更改为Key - Expire,不需要查看rakmsanf ,esmsanf,esmmwrd,m5zn,quantity,w7da,reorder(更改所选标题名称)

2 个答案:

答案 0 :(得分:0)

您可以按以下方式更改SQL

Select rakmsanf  as  [-رقم الصنف] ,esmsanf as Expire from Items  Where m5zn ='N'

然后您不需要通过代码

来完成

答案 1 :(得分:0)

您可以在此ff中更改Datagridview Column标头。步骤进行:

  1. 右键单击datagridview
  2. 然后选择要编辑标题名称的列,在属性上,有标题文本,您可以在其中编辑数据网格视图的标题名称。
  3. 希望它有效。