Hello, I'm building a custom tree into a form using FormTreeControl. The tree has different types of data behind each node, depending upon the level in the hierarchy, so I cannot use the FormTreeDatasource. This has lead to several questions for which I cannot find solutions, even though they seem like they could be resolved relatively simply. I was hoping some experts here could kindly provide some advice and pointers.
The form is split vertically, with a Grid on the top (bound to a datasource), and the bottom is split horizontally, with a tree on the left, and some simple form fields on the right. The idea is someone selects an item from the list in the top pane, and the form builds a tree showing a BOM structure for that item. (Mind you, this BOM structure is not the Axapta BOM tables, but is stored in custom tables that are populated from our separate manufacturing system.) Then, when a user selects an item from the tree, the fields on the right are populated with values from the table behind that particular item in the tree. First, I need to catch the event of a selection change in the Grid to call a method on the tree (passing it a parameter from the Grid's datasource for the newly selected record) to build the tree's contents. If it was a TreeDatasource, this would be easy because it would be bound to a datasource, and the query would automatically refresh the tree. However, because the tree is more complex (different data sources behind different levels in the hierarchy), I cannot depend on the query. The Grid control doesn't have a "selectionChanged" event like the FromTreeControl does. I found some example code in the tutorials showing how to catch the mouseDown event and use [curNode] = hitTest( _x, _y); but how do I translate the resulting Node object into a record in the data source? Once i have a cursor into that record, I think I'll be all set linking the two together. Any ideas here? Second, when adding a TreeItem to the FormTreeControl, one of the parameters you can pass is "_data," which is of type anyType. I thought it would be convenient to pass a table record in there, which I could pull back out on selectionChanged in order to assign the values in the record into the form elements on the right. The tutorial for formTreeControl does something similar, but it doesn't use the _data parameter. How can I cast that anyType object back to its strong type so that I can use it? C-like sytax (type)variable or type(variable) don't seem to work in X++ and I can't find anything on typecasting on Google or in the newsgroups. The only work-around I can think of would be to store a simple data type of the primary key into the table, and doing a select firstonly using that value in selectionChanged. Any ideas? Finally, because the tree has different types of data on it depending on the level in the hierarchy, once I place _data into it, I will need to know be able to directly infer the type of the_data before I cast it. In most C-like laguages, I would be able to use typeof to do a switch on variable, and perform my logic differently in each case. typeof isn't a reserved word in X++... Is there a different syntax for this, or is there a workaround I could use? I suppose if I had no other option, I could keep track of the depth in the tree to infer the type of the data, but I was hoping (for code reuse) that I wouldn't have to couple the organization of the tree to the data so tightly. Thanks in advance, Tim