We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Searching a Node in Runtime

I have a requirement where I need to search for a Node dynamically in Runtime and Select it. Consider the following Scenario. I have a ToolBox wherefrom I am dragging and dropping Symbols into the Diagram area. I have custom ports attached to these Symbols and the no: of these ports depend upon the type of the Symbol. These Symbols are connected using Links. Each Symbol is identified by a Unique property called Instance No:. I have a Search button in my menu which brings out a Search Screen where this is a textbox and a Search button. Say for example the user types in X156 in the textbox area. X156 in this case is the unique Instance Number. When the user clicks the Search button I should be able to programmatically select the Symbol X156 in my diagram worksheet. How can I do it ? Regards, Vinod

5 Replies

MF Meera Fathima Syncfusion Team November 22, 2005 12:07 PM UTC

Hello Vinod, Here is a sample code snippet that shows how to select symbols according to the symbol''s unique id name at run time. private void Search_button_Click (object sender, System.EventArgs e) { INode curnode; foreach (INode tempLoopVar_curnode in this.diagram1.Model.Nodes) { curnode = tempLoopVar_curnode; MySymbol sym = ((MySymbol) curnode); SymbolLabel lbl; foreach (SymbolLabel tempLoopVar_lbl in sym.Labels) { lbl = tempLoopVar_lbl; if (lbl.Text == this.textBox1.Text) { this.diagram1.SelectionList.Clear(); this.diagram1.Controller.SelectionList.Add(sym); this.diagram1.Controller.View.Draw(); this.diagram1.Controller.View.Refresh(); } } } } In the above code, this.diagram1.Controller.SelectionList.Add(sym) will let you select the specified symbol. I hope this will give you an idea about what you are seeking. Please let me know if you need further assistance on this issue. Thanks and Regards, Meera.


AD Administrator Syncfusion Team November 24, 2005 04:56 AM UTC

Hello Meera, Further referring to the above code we were able to make the auto selection of the symbol. > >Hello Vinod, > >Here is a sample code snippet that shows how to select symbols according to the symbol''s unique id name at run time. > >private void Search_button_Click (object sender, System.EventArgs e) > { > INode curnode; > foreach (INode tempLoopVar_curnode in this.diagram1.Model.Nodes) > { > curnode = tempLoopVar_curnode; > MySymbol sym = ((MySymbol) curnode); > > SymbolLabel lbl; > foreach (SymbolLabel tempLoopVar_lbl in sym.Labels) > { > lbl = tempLoopVar_lbl; > if (lbl.Text == this.textBox1.Text) > { > this.diagram1.SelectionList.Clear(); > this.diagram1.Controller.SelectionList.Add(sym); > this.diagram1.Controller.View.Draw(); > this.diagram1.Controller.View.Refresh(); > } > } > } > } > >In the above code, this.diagram1.Controller.SelectionList.Add(sym) will let you select the specified symbol. I hope this will give you an idea about what you are seeking. > >Please let me know if you need further assistance on this issue. > > >Thanks and Regards, >Meera. > > >


AD Administrator Syncfusion Team November 24, 2005 04:56 AM UTC

Hello Meera, Further referring to the above code we were able to make the auto selection of the symbol. > >Hello Vinod, > >Here is a sample code snippet that shows how to select symbols according to the symbol''s unique id name at run time. > >private void Search_button_Click (object sender, System.EventArgs e) > { > INode curnode; > foreach (INode tempLoopVar_curnode in this.diagram1.Model.Nodes) > { > curnode = tempLoopVar_curnode; > MySymbol sym = ((MySymbol) curnode); > > SymbolLabel lbl; > foreach (SymbolLabel tempLoopVar_lbl in sym.Labels) > { > lbl = tempLoopVar_lbl; > if (lbl.Text == this.textBox1.Text) > { > this.diagram1.SelectionList.Clear(); > this.diagram1.Controller.SelectionList.Add(sym); > this.diagram1.Controller.View.Draw(); > this.diagram1.Controller.View.Refresh(); > } > } > } > } > >In the above code, this.diagram1.Controller.SelectionList.Add(sym) will let you select the specified symbol. I hope this will give you an idea about what you are seeking. > >Please let me know if you need further assistance on this issue. > > >Thanks and Regards, >Meera. > > >


AD Administrator Syncfusion Team November 24, 2005 05:15 AM UTC

Hello Meera, The above code worked for selection of any symbol based on search code provided by you! But some how the worksheet fails to scroll to the location of the searched symbol, though the symbol is still identified and appears selected. Please provide a solution! Thanks and Regards, Srikumar


MF Meera Fathima Syncfusion Team November 30, 2005 10:57 AM UTC

Hello Srikumar, I am sorry about this delay in getting back to you on this issue.You need to set the View.Origin property within the search () method to scroll the diagram''s view automatically at the selected node''s location. Here is the sample code snippet for that. private void Search_button_Click (object sender, System.EventArgs e) { INode curnode; //............ if (lbl.Text == this.textBox1.Text) { this.diagram1.SelectionList.Clear(); this.diagram1.Controller.SelectionList.Add(sym); this.diagram1.Controller.View.Origin = sym.Location; // Scrolls the diagram''s view at the specified location. this.diagram1.Controller.View.Draw(); this.diagram1.Controller.View.Refresh(); } // ........ } I hope the above information will help you. Thanks and Regards, Meera.

Loader.
Live Chat Icon For mobile
Up arrow icon