一个继承自datagridview的WF控件的问题

发布时间:2024-05-14 12:01 发布:上海旅游网

问题描述:

一个继承自datagridview的WF控件的问题
一个继承自datagridview的WF控件
public void InitializeC()
{
DataSet ds = new DataSet();
if (File.Exists(this.pBDataWindowsFilePathAndName))
{
// MessageBox.Show(this.pBDataWindowsFilePathAndName);
ds.ReadXml(this.pBDataWindowsFilePathAndName);
//this.DataSource = ds.Tables[0];
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
if (!this.Columns.Contains(ds.Tables[0].Rows[i]["name"].ToString()))
{
this.Columns.Add(ds.Tables[0].Rows[i]["name"].ToString(), ds.Tables[0].Rows[i]["text"].ToString());
this.Columns[ds.Tables[0].Rows[i]["name"].ToString()].DataPropertyName = ds.Tables[0].Rows[i]["name"].ToString();
this.Columns[ds.Tables[0].Rows[i]["name"].ToString()].Width = int.Parse(ds.Tables[0].Rows[i]["Columnwidth"].ToString()) / 3;
}
}
}

}

private string pBDataWindowsFilePathAndName = “”
[Browsable(true), Category("liruiba_DGVClass"), Description("XML地址")]
public string PBDataWindowsFilePathAndName
{
get
{
return this.pBDataWindowsFilePathAndName;
}
set
{
this.pBDataWindowsFilePathAndName = value;
}
}

我把InitializeC()写在构造函数里, this.pBDataWindowsFilePathAndName 这个一直都 是空值
要是把InitializeC()放在了protected override void OnPaint(PaintEventArgs pe)这里面,,this.pBDataWindowsFilePathAndName 可以接收到值。但会一直循环加列,不会停止。。
要怎么解决呀 ???
pBDataWindowsFilePathAndName 属性变更事件 是哪个呀

问题解答:

你的处理写在那里有很多种选择,重要的是你希望在什么时候干什么?
看你的程序,你是想在设定了XML文件后,将文件的内容绑定到DGV上。
如果想做这个处理,关键事件是pBDataWindowsFilePathAndName 是否有值。

那么,你的处理写在pBDataWindowsFilePathAndName 的值变更的时候是最好的。就是说,在属性变更的时候,调用你写的那个InitializeC函数。

热点新闻