reflecting an object values which is in the memory on the GUI?
I have an object in the memory and I want to link this object with GUI component and I want this component to mirror the object status(values)....
i.e. I want to see the object values that is in the memory right now and I want the GUI to 开发者_如何转开发reflect the object status always how can I do this?This is a very common pattern in development and is called Data Binding. .NET has some great support for data binding, it is a large topic and too big for a simple answer here. But here is a link to an MSDN article that will get you started.
http://msdn.microsoft.com/en-us/library/ms752347.aspx
If you are using WinForms, the PropertyGrid
component is what you want:
public Form1() {
// The initial constructor code goes here.
PropertyGrid propertyGrid1 = new PropertyGrid();
propertyGrid1.CommandsVisibleIfAvailable = true;
propertyGrid1.Location = new Point(10, 20);
propertyGrid1.Size = new System.Drawing.Size(400, 300);
propertyGrid1.TabIndex = 1;
propertyGrid1.Text = "Property Grid";
this.Controls.Add(propertyGrid1);
propertyGrid1.SelectedObject = textBox1;
}
Here, textBox1
is being "inspected". It can be any object. It displays it like the property inspector you see in Visual Studio.
精彩评论