日期:2014-05-17 浏览次数:20988 次
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.InitialDirectory = "E:\\";//注意这里写路径时要用c:\\而不是c:\
openFileDialog.Filter = "文本文件
------解决方案--------------------
*.*
------解决方案--------------------
C#文件
------解决方案--------------------
*.cs
------解决方案--------------------
所有文件
------解决方案--------------------
*.*";
openFileDialog.RestoreDirectory = true;
openFileDialog.FilterIndex = 1;
string fName = "";
int rowcount = this.dataGridView1.Rows.Count;
this.dataGridView1.Columns.Add("ID", "编号");
this.dataGridView1.Columns.Add("FilePath", "文件路径");
this.dataGridView1.Columns.Add("FileState", "文件状态");
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
DataGridViewComboBoxCell combox = new DataGridViewComboBoxCell();
combox.Items.Clear();
combox.Items.Add("启用");
combox.Items.Add("停用");
DataGridViewRow dr = dataGridView1.Rows[rowcount];
fName = openFileDialog.FileName;
dr.Cells[0].Value = rowcount.ToString();
dr.Cells[1].Value = fName;
dr.Cells[2] = combox;
dr.Cells[2].Value = combox.Items[0];
}