how to get the group's name when click a vertex?

Dec 21, 2012 at 1:26 PM

  I have grouped the graph's vertices by ConnectedComponent algorithm. The data is stored into groupInfo. I want to implement the collapse-expand function. But I don't know how to get the group's name when I click nodexl. I wrote two subMenu in nodexl's contextMenu. One is collapse-subMenu_click, the code looks like this:

foreach (GroupInfo group in groupInfo)
                if (group.Vertices.Contains(everyClickedVertex))
                    nodexl.CollapseGroup(group.Name, true);


   The vertex clicked everytime is saved by everyClickedVertex. Another function is expand_subMenu. I wrote the code like this:

Dictionary<string, IVertex> dicCollapseGroup = nodexl.CollapsedGroups;
            var enumGroupKey = dicCollapseGroup.Where(p =>   p.Value == everyClickedVertex).Select(p => p.Key);
            if (enumGroupKey.Count() != 0)
                string groupName = (string)enumGroupKey.ElementAt(0);
                nodexl.ExpandGroup(groupName, true);  


I feel like an idiot. So dear tcap479, can you tell me a better way to get the group's name?
Dec 21, 2012 at 5:53 PM
Edited Dec 21, 2012 at 8:31 PM


I'm not sure I understand the problem you need to solve or what your code is doing.  I'll assume, based on your discussion title, that you need to retrieve the name of the group a vertex belongs to when that vertex is clicked.

One way to do that is the following:

1. In the code that puts vertices into groups, store the group name within each vertex object.  You can do that with the IVertex.SetValue() method, which allows you to store arbitrary key/value pairs on the vertex.  For example:

    myVertex.SetValue("GroupName", "GroupA").

2. In the NodeXLControl.VertexClick event handler, retrieve the value that you stored on the vertex:

    Object groupNameAsObject;
    if ( e.Vertex.TryGetValue("GroupName", out groupNameAsObject)  )
        Do something with (String)groupNameAsObject;

If that's not what you're asking, let me know.

-- Tony

Dec 22, 2012 at 4:08 AM

oh, I see, I lost this code - myVertex.SetValue("GroupName", "GroupA"). So I have to search the nodexl's CollapsedGroups to find the group's name.

Thanks a lot! :) :) :P