private void Main_Load(object sender, EventArgs e) { try { //xml文件路径 string path = @"Test.xml"; //读取文件 DataSet ds = new DataSet(); if (File.Exists(path)) { ds.ReadXml(path); } dataGridView1.DataSource = ds.Tables.Count > 0 ? ds.Tables[0] : null; //加工dataGridView1 #region 加列标题测试 dataGridView1.Columns[0].HeaderText = "制令单号"; dataGridView1.Columns[1].HeaderText = "成品编号"; dataGridView1.Columns[2].HeaderText = "生产数量"; dataGridView1.Columns[3].HeaderText = "来源单号"; #endregion DataGridViewColumnSelector columnSelector = new DataGridViewColumnSelector(dataGridView1); } catch (Exception ex) { MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
8、执行程序,在任意DataGridView标题栏右击,即可弹出菜单:
总结