操作如下:
相關變量:
private System.Windows.Forms.OpenFileDialog ofdlg;
private System.Windows.Forms.DataGridView dgvContext; private void btnBrowser_Click(object sender, EventArgs e)
{
string filename = string.Empty;
if (ofdlg.ShowDialog() == DialogResult.OK)
{
filename= ofdlg.FileName;
txtFileName.Text = filename;
GetConfigurationContext(filename);
}
} private void GetConfigurationContext(string filename)
{
FileInfo fileInfo = new FileInfo(filename);
DataSet ds = new DataSet();
ds.ReadXml(filename); DataView dv = ds.Tables[1].DefaultView;
if (ds.Tables[1].Columns.IndexOf("lockItem")!=-1)
{
dv.RowFilter = "lockItem='false'";
} dgvContext.DataSource = dv;
} 我以上面的方法把XML的內容用datagridview()顯示出來,但是每當我打開一次文件,之前的內容都還會存在,應該怎麼做,之前的內容才可以清除呢?
相關變量:
private System.Windows.Forms.OpenFileDialog ofdlg;
private System.Windows.Forms.DataGridView dgvContext; private void btnBrowser_Click(object sender, EventArgs e)
{
string filename = string.Empty;
if (ofdlg.ShowDialog() == DialogResult.OK)
{
filename= ofdlg.FileName;
txtFileName.Text = filename;
GetConfigurationContext(filename);
}
} private void GetConfigurationContext(string filename)
{
FileInfo fileInfo = new FileInfo(filename);
DataSet ds = new DataSet();
ds.ReadXml(filename); DataView dv = ds.Tables[1].DefaultView;
if (ds.Tables[1].Columns.IndexOf("lockItem")!=-1)
{
dv.RowFilter = "lockItem='false'";
} dgvContext.DataSource = dv;
} 我以上面的方法把XML的內容用datagridview()顯示出來,但是每當我打開一次文件,之前的內容都還會存在,應該怎麼做,之前的內容才可以清除呢?
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货