日期:2014-05-18 浏览次数:21072 次
public Demo2() { InitializeComponent(); //读取数据到DataSet(代码略) dgvInfo.DataSource = ds.Tables[0]; System.Windows.Forms.DataGridViewTextBoxColumn ProductName = new DataGridViewTextBoxColumn(); ProductName.DataPropertyName = "productname"; ProductName.HeaderText = "商品名称"; ProductName.Name = "ProductName"; ProductName.Resizable = System.Windows.Forms.DataGridViewTriState.True; dgvInfo.Columns.Clear(); [color=#FF0000]clear()方法没有清除显示数据 [/color] dgvInfo.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { ProductName }); }
string path = "c:\\test\\abc.txt"; string date = DateTime.Now.ToString().Replace("-", "").Replace(":", "").Replace(" ", ""); path = path.Replace(".", "_" + date +"."); //有日期的 path = path.Substring(0, path.IndexOf("_")) + path.Substring(path.IndexOf("."));//去掉日期的 string path = "c:\\test\\abc.txt"; string date = DateTime.Now.ToString().Replace("-", "").Replace(":", "").Replace(" ", ""); path = path.Replace(".", "_" + date +"."); //有日期的 path = path.Substring(0, path.IndexOf("_")) + path.Substring(path.IndexOf("."));//去掉日期的
------解决方案--------------------
加上
dgvInfo.AutoGenerateColumns = false;
------解决方案--------------------