Sunday, January 14, 2007

TreeView Problems in Smart Client Software Factory + CAB

I was playing around with the new Smart Client Software Study to do a feasibility study on this project I need to accomplish. A lot of my experiments are an effort to understand the SCSF and the CAB so I would highly appreciate it if I were to get any kind of guidance for the same.

So last night, I started playing around with the SCSF by creating a new solution with an additional Interface.Layout project as shown in fig 1.




Once that was done, I modified the ShellLayoutView to contain the Outlook style Navigation Pane created by Ascend.Net Controls (get that from CodePlex). This can be seen in Fig 2. I also added a TreeView control that would help me in navigating to different smart parts or modules based on the selection.


Once that was added, I added the code to expose the TreeView in the ShellLayoutView.cs as shown:

internal TreeView CustomerTreeView
{
get { return customerTreeView; }
}

After that, I wanted to add a command handler to the tree whenever a node was double-clicked. So I went ahead and added the following lines of code in the shellLayoutViewPresenter.cs


WorkItem.Commands[CommandNames.HandleCustomerTreeEvent].AddInvoker(View.CustomerTreeView, "NodeMouseDoubleClick");


Note that the CommandNames was also updated with the HandleCustomerTreeEvent (in the Infrastructure project]

I compiled and ran the solution just to make sure everything showed up correctly and this is how it looked when I did that:



I also added a Business Module to show a Smart Part called CustomerFindView whenever the FindCustomer Node was double clicked.


Here's how that looked:


In the ModuleController, I added the following CommandHandler code in order to process the node mouse double click event:

[CommandHandler(CommandNames.HandleCustomerTreeEvent)]
public void ShowFindCustomerLayout(object sender, System.Windows.Forms.TreeNodeMouseClickEventArgs e)
{
if (e != null && e.Node != null && !String.IsNullOrEmpty(e.Node.Tag.ToString()))
{
switch (e.Node.Tag.ToString())
{
case "findCustomer":
ShowFindCustomerView();
break;
default:
break;
}
}
}

Where the ShowFindCustomerView() method would be as simple as:


FindCustomerView mFindView = WorkItem.SmartParts.AddNew();
WorkItem.Workspaces[WorkspaceNames.RightWorkspace].Show(mFindView);

Now this compiles fine. Everytime I try to run it though, it fails saying:

"Error binding to target method."

I am pretty sure that it cannot bind to the NodeMouseDoubleClick event. I removed the Command Handler code and that seemed to work fine again, but now I cannot handle the double click event.

I tried the same, by replacing the TreeView with a Button. I exposed the Button in the ShellLayoutView.cs, added the CommandHandler to the "click" event in the ShellLayoutViewPresenter.cs and added the CommandHandler for the button in the Modulecontroller.cs for the CustomerModule and that seemed to work fine.

Am I missing something out here? Any help would be appreciated.

1 comment:

SpreadSmile said...

did u solve the error for click event in treeview??
i am having the same problem....