Hi,
Im wondering how to change text in column at runtime.
By doing that i can update text summary in system
Thankyou
InfoNode5 is obviously there to simply demo how to do columns and rows of text more than to be the ultimate interface to a node with a table of text in it.
// find column using header text
GoListGroup body = FindBody();
if (body == null) return null;
GoListGroup table = body[1] as GoListGroup;
if (table == null) return null;
GoListGroup lg = o as GoListGroup;
if (lg != null) {
GoText gtx = lg[0] as GoText;
if (gtx != null && gtx.Text == header) return lg;
}
}
return null; // not found
}
foreach (GoObject o in this) {
GoListGroup lg = o as GoListGroup;
if (lg != null) return lg;
}
return null;
}
GoListGroup lg = this.FindColumn(header);
if (lg != null) {
GoText gtx = lg[index] as GoText;
if (gtx != null) gtx.Text = text;
}
}
[/code]
ThankYou…Jake
I got the code and it work fine in a single file.
I have the problem regarding how to address this when it come with separated file class.
public GoListGroup FindBody() {
foreach (GoObject o in <u><b>this</b></u>) {
GoListGroup lg = o as GoListGroup;
if (lg != null) return lg;
}
return null;
}
Sorry, I should have been more clear. That’s all code that gets dropped into the InfoNode5 class.
Yeah…i put all the code into infoNode5 class.
When i call inside button event at Mainform
like this
{
infoNode5 n = new infoNode5();
n.SetColumnText(“Enlisted”, 3, “33333”);
}
then the message error shows:
“Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index”
Does your infonode5 still initialize the columns the way the sample does?
Yes…
When form load
{
GraphDoc.AddStuff(goPalette1.Document, true);
}
//in GraphDoc
addstuff(GoDocument doc, bool palette)
{
doc.StartTransaction();
InfoNode5 info5 = new InfoNode5();
info5.Initialize();
info5.Position = new PointF(250, 810);
goPalette1.Document.Add(info5)
doc.FinishTransaction(“Finish Added”);
}
then F5 Program success and load the column in palette
then i do drag into childForm just like sample demo1
when i do button click event in parrentform which contain code
{
infoNode5 n = new infoNode5();
n.SetColumnText(“Enlisted”, 3, “33333”);
}
the error message occur
Please tell me where i do wrong…Thankyou
Well, the code I gave doesn’t check to see if the GoListGroup has enough elements before it does
It would help to call Initialize to set things up so that it has the parts that you want to modify.
im not modify any code in infoNode5
so “Enlisted” column should have 5
I do another win project…and this time i able to use your code and success modify at runtime.
- I put goView1 in Form1
then put button1 [to load cloumn in goView1] and do click event like this
{this.Initialize();}
then put button2 [modify at real time] and do also click event
{ SetColumnText(“Enlisted”, 3, “33333”);}
In the Form1 Code i put
Initialize()
{content not change with infoNode5}
private GoListGroup MakeColumn(String head)
{ GoListGroup c = new GoListGroup();
c.Selectable = false;
c.LinePen = null;
c.Alignment = GoObject.MiddleLeft;
GoText header = MakeText(head);
header.Underline = true;
c.Add(header);
return c;
}
private GoText MakeText(String s)
{
GoText t = new GoText();
t.Selectable = false;
t.FontSize = 7;
t.Text = s;
t.Alignment = GoObject.Middle;
return t;
}
And follow is from Jake
#region From Jake
public GoListGroup FindColumn(string header)
{
// find column using header text
GoListGroup body = FindBody();
if (body == null) return null;
// body GoListGroup has 2 items.
GoListGroup table = body[1] as GoListGroup;
if (table == null) return null;
foreach (GoObject o in table)
{
GoListGroup lg = o as GoListGroup;
if (lg != null)
{
GoText gtx = lg[0] as GoText;
if (gtx != null && gtx.Text == header) return lg;
}
}
return null; // not found
}
public GoListGroup FindBody()
{
foreach (GoObject o in <b>this.goView1.Document</b>)
{
GoListGroup lg = o as GoListGroup;
if (lg != null) return lg;
}
return null;
}
public void SetColumnText(string header, int index, string text)
{
GoListGroup lg = this.FindColumn(header);
if (lg != null)
{
GoText gtx = lg[index] as GoText;
if (gtx != null) gtx.Text = text;
}
}
#endregion
Finally F5 and success load the column when button1 is click
and column is modified when button2 is click
PS: Bold is modify code from original
But this is not what i want…
no… you want the FindBody to iterate the items in “this”… the list of items in the GoNode (GoGroup).
Yes u are right. I think what if replace this with something else that refer to object in GraphViewWindows
You shouldn’t have to replace the “this”
foreach (GoObject o in this) {