Adding ListView to GoView

Hello,

I added a ListView to my GoView by issuing

this.Controls.Add(listView)

but cant move or resize the list.

How can i achieve that?

I understand that i have to use GoControl, but can’t figure out how.
Is there any example available?

Thanks in advance.

I assume you have already searched the sample application sources for uses of GoControl.
If you want an unadorned WinForms Control, just use a GoControl:
GoControl co = new GoControl();
co.Bounds = new RectangleF(100, 100, 200, 46);
co.ControlType = typeof(TrackBar);
goView1.Document.Add(co);
TrackBar tb = co.GetControl(goView1) as TrackBar;
if (tb != null) {
tb.BackColor = Color.ForestGreen;
tb.Minimum = 0;
tb.Maximum = 100;
tb.SmallChange = 5;
tb.TickFrequency = 5;
tb.TickStyle = TickStyle.Both;
}
Note that you have to initialize the Control, and you need to do any event handling and focus management. The user can select this GoControl and can resize it. (But apparently the TrackBar control determines its own Height; you won’t have that limitation with most other Controls.)
To make it easier to select and drag the Control, you have to make it easier to select and drag the GoControl. You can do that by using a GoGroup consisting of a GoRectangle that provides a selectable border and a GoControl to host the Control:
[Serializable]
public class ControlGroup : GoGroup {
public ControlGroup() {
myBackground = new GoRectangle();
myBackground.Selectable = false;
myBackground.Brush = new HatchBrush(HatchStyle.Percent30, Color.DarkBlue, Color.White);
Add(myBackground);
myGoControl = new GoControl();
myGoControl.Selectable = false;
Add(myGoControl);
}
protected override void CopyChildren(GoGroup newgroup, GoCopyDictionary env) {
base.CopyChildren(newgroup, env);
ControlGroup cg = (ControlGroup)newgroup;
cg.myBackground = (GoShape)env[myBackground];
cg.myGoControl = (GoControl)env[myGoControl];
}
public override void Remove(GoObject obj) {
base.Remove(obj);
if (obj == myBackground)
myBackground = null;
else if (obj == myGoControl)
myGoControl = null;
}
public override void LayoutChildren(GoObject childchanged) {
RectangleF b = this.Bounds;
if (this.Background != null) this.Background.Bounds = b;
if (myGoControl != null) {
RectangleF r = b;
r.Inflate(-3, -3);
myGoControl.Bounds = r;
}
}
public GoShape Background {
get { return myBackground; }
}
public GoControl GoControl {
get { return myGoControl; }
}
public Type ControlType {
get { return this.GoControl.ControlType; }
set {
// force any existing Controls to be removed
this.GoControl.Visible = false;
this.GoControl.ControlType = value;
// cause any Controls to be re-created and shown
this.GoControl.Visible = true;
}
}
private GoShape myBackground;
private GoControl myGoControl;
}
Then you could use this as a generic Control holder:
ControlGroup cg = new ControlGroup();
cg.Bounds = new RectangleF(100, 200, 200, 46);
cg.ControlType = typeof(TrackBar);
goView1.Document.Add(cg);
TrackBar trackbar = cg.GoControl.GetControl(goView1) as TrackBar;
if (trackbar != null) {
trackbar.BackColor = Color.ForestGreen;
trackbar.Minimum = 0;
trackbar.Maximum = 100;
trackbar.SmallChange = 5;
trackbar.TickFrequency = 5;
trackbar.TickStyle = TickStyle.Both;
}
Or use with any kind of Control, all here uninitialized:
ControlGroup cg = new ControlGroup();
cg.Bounds = new RectangleF(100, 300, 100, 50);
cg.ControlType = typeof(TextBox);
goView1.Document.Add(cg);
cg = new ControlGroup();
cg.Bounds = new RectangleF(100, 400, 100, 50);
cg.ControlType = typeof(ProgressBar);
goView1.Document.Add(cg);
cg = new ControlGroup();
cg.Bounds = new RectangleF(100, 500, 100, 50);
cg.ControlType = typeof(TabControl);
goView1.Document.Add(cg);
cg = new ControlGroup();
cg.Bounds = new RectangleF(100, 600, 100, 50);
cg.ControlType = typeof(ListView);
goView1.Document.Add(cg);
You can also try the TreeViewNode example class, which you can download from http://www.nwoods.com/forum/uploads/<SPAN =highlight>TreeViewNode.cs. You can also search this forum for other mentions of GoControl.