locked
Displaying Hierarchical Data In LightSwitch ? RRS feed

  • Question

  • I have a requirement to display hierarchical data in LightSwitch and presume a SilverLight treeview inside a custom control is the way to go ?

    Great, but I have no SL experience!

    The data in question is bill-of-material information and is contained within one table. A ParentPartNumberID field is used to associate child parts with a parent part, and complex structures can result in a hierarchy 4 or 5 levels deep.

    I've come across this post:

    http://social.msdn.microsoft.com/Forums/en-US/lsextensibility/thread/bcdaa86f-459a-47d3-853a-3c5e56eb088a

    But there seems a lot to it, and any pointers would be appreciated.

    I have created a test SL control and bound it to some LS data, but the tree showed no data.

    I'm suspecting that I might need to populate the tree in code ( this is how I did it in WinForms ), but I'm not sure if the SL treeview can be populated manually from within LS ?

    If anyone has done something like this I would be grateful for any help you can offer...

    Thanks,

    Nick  

    Thursday, July 14, 2011 5:29 PM

All replies

  • Hi Nick,

    I have a similar requirement for one of the entities in my application and I'm going to do the "poor man's tree" by using a grid and indenting the display column using tabs (or spaces) to give a tree-like experience. I've briefly tested this a month ago and thought it would work.

    If you could base your grid query on a view you could return an integer column indicating the number of levels for the current item and then create a computed DisplayDescription property of type string which is a concatenation of the appropriate number of tabs (or spaces) to show the indentation (based on the integer column giving the level number) and the normal display description you would use.

    Another way would be to concatenate the DisplayDescription inside the view itself which should give better sorting options as computed properties aren't sortable.

    Hope this helps.


    Xander
    Thursday, July 14, 2011 9:46 PM
  • That's interesting. What about expanding and closing the nodes?
    Friday, July 15, 2011 4:32 PM
  • The "poor man's tree" unfortunately does not allow expanding and closing nodes :) In my case that is fine as the tree will not be that big.

    However, thinking as I'm going here... two possible options spring to mind:

    1) A possible "poor man's work-around' might be to have a set of [Expand] and [Contract] buttons next to the grid that filters out all records with an indentation level greater than a given starting display level - say 1 to initially only show root level nodes. The query used for the grid would then use the display level to filter out all records with a Level greater than the display level (either as a parameterized query or just pre-processing the query). Clicking [Expand] would add one to the display level and refresh the grid. Clicking on [Contract] would decrease the display level by one and refresh the grid.

    2) Another (not so nice) option would be to include a boolean flag on each node in the database to say whether it is expanded or contracted and have a button next to the grid that updates that flag back to the server and refreshes the grid, but then it would apply to all users which would not be ideal.You could also have a Display link table between Users and Nodes to set such a flag per user, but this is now getting messy and probably isn't a good idea.... let's can this one.

    I can see option 1 being workable for some scenarios although it will of course contract and expand the entire tree, rather than a specific node only... (disclaimer: I've not tried this).

    Regards


    Xander



    Friday, July 15, 2011 11:01 PM
  • :) Very interesting. I like the way you find workaround. Your poor man's version will soon be rich. Keep it up. How about reporting? Is there a poor man's version?
    Saturday, July 16, 2011 8:35 AM
  • Haha... up to recently it would have been the new DevExpress Xtra Reporting suite which was going to be free. They are now however going to charge for it, but at $99 it will still suit a poor man's pockets :)
    Xander
    Saturday, July 16, 2011 8:42 AM
  • :)

    What are the other options available? Why Microsoft did not include a reporting module is beyond me. Its targeted to business, which business will not print report. Do they have another reporting product comming out or something? 

    Saturday, July 16, 2011 9:17 AM
  • Haha... up to recently it would have been the new DevExpress Xtra Reporting suite which was going to be free. They are now however going to charge for it, but at $99 it will still suit a poor man's pockets :)
    Xander


    I agree. Not everyone needs professional reports. Many people are fine just using the Export to Excel.

    For those who need reports, $99 is a fair price.


    http://www.adefwebserver.com

    http://LightSwitchHelpWebsite.com

    Saturday, July 16, 2011 1:50 PM
  • How do you format the data you export out to Excel? Write codes? Any samples? For browser, this excel export is not available. So how are you going to print?

    Saturday, July 16, 2011 2:40 PM
  • How do you format the data you export out to Excel? Write codes? Any samples? For browser, this excel export is not available. So how are you going to print?


    Excel has built in formating for printing

    For LightSwitch web browser apps see:

    Printing Sql Server Reports (.rdlc) With LightSwitch

    Printing With LightSwitch


    Make Them Ask: That's a LightSwitch App?

    http://LightSwitchHelpWebsite.com

    Monday, July 18, 2011 2:15 PM
  • Thank you for the links.
    Monday, July 18, 2011 3:34 PM