APL/W Grid Object versus WPF DataGrid

Using (or providing) Microsoft.NET Classes

APL/W Grid Object versus WPF DataGrid

Postby Dick Bowman on Mon Jul 05, 2010 10:40 am

I'm exploring WPF - wondering whether it is sensible to use this to define the user interface for new applications rather than APL/W's inbuilt controls.

For most controls things look rather equally balanced from the application developer perspective (I can make a richer look/feel if I use WPF, at the price of increasing complexity - I have .xaml files to keep synchronised with my APL code).

But I hit a big comprehension gap with the WPF DataGrid - it may be that overcoming this gap will help me make better use of WPF generally - and I don't know how to resolve it.

The APL/W Grid object has grown on me over the years, it sits there in most of my application forms and is straightforward to use - at its simplest, assign a matrix to the Values property, pick out elements by indexing (function, of course - no square brackets chez Dick).

But I can't figure out how to do this - Jonathan's 2008 WPF example seems to contain some hints, but everything seems alarmingly long-winded. I get a sense that Microsoft have a programming model where data always sits inside databases and there's no scope for "make me a five-row, four column grid that I'll fill in as and when I feel like it".

Anybody able to do any enlightening?
Visit http://apl.dickbowman.com to read more from Dick Bowman
User avatar
Dick Bowman
 
Posts: 235
Joined: Thu Jun 18, 2009 4:55 pm

Re: APL/W Grid Object versus WPF DataGrid

Postby StefanoLanzavecchia on Mon Jul 05, 2010 5:21 pm

Dick Bowman wrote:[...]
But I hit a big comprehension gap with the WPF DataGrid - it may be that overcoming this gap will help me make better use of WPF generally - and I don't know how to resolve it.
[...]
Anybody able to do any enlightening?


The folks at Dyalog are aware of this issue. The way I see it is that the WPF Datagrid, unlike Dyalog's grid, is a way to display and interact with tabular data (where each record contains fields, all of the same type) rather than matrix data (where each cell can be of a different kind). This means that a lot of effort went into simplifying dealing with such data.

For a fair comparison, you should be looking for a component like the Farpoint Spread (which doesn't seem to exist in the WPF world... yet?) where you aren't limited to a DB table data source.

Or build a data provider that has a dual interface: a table-like appearance so that it can be consumed by the various grids, and a matrix-like appearance so that it looks nice from an APL perspective.
User avatar
StefanoLanzavecchia
 
Posts: 109
Joined: Fri Oct 03, 2008 9:37 am

Re: APL/W Grid Object versus WPF DataGrid

Postby MikeHughes on Mon Jul 05, 2010 7:04 pm

Hi Dick,

I have used the WPF grids from DV Express and from Rad controls as I was evaluating them prior to deciding which to use for my next application. This was before WPF version 4 - where there was no native grid. With them it was very easy to have a grid of APL data behind the WPF control - I am assuming that the native one will work the same.

I will look at the new WPF data grid tonight and try and post the equivalent tomorrow.

By just trying to build controls that match the APL/W ones you are missing so much more. There are routed events, commands, dependency properties as well as theming and layoutout panels to look at. There is so much more that can be utilised - not just the bare controls that are offered.

There is native support for XPS documents as well. The list just goes on and on.....

With relatively little work you could define a WPF control called BowmanGrid that had a property called values which WOULD be an APL array.
User avatar
MikeHughes
 
Posts: 86
Joined: Thu Nov 26, 2009 9:03 am
Location: Market Harborough, Leicestershire, UK

Re: APL/W Grid Object versus WPF DataGrid

Postby MikeHughes on Mon Jul 05, 2010 9:51 pm

Dick,

You might wish to try this as a quick start. I havent added any event handlers - its just a quick demo - nothing fancy (or clean) but it works. The nice thing is the link between dt (Data Table) and the grid. Hopefully you can copy and paste the function below - check the locations of your dlls. No xaml is needed - its just nicer when you use the tools to develop the GUIs

You may not need all the []using s, I reduced the list a bit but got bored so some may be redundant.

I am starting to develop an application so I'm also starting to build the tools to use WPF properly - I'll happily let you see them at one of the meetings of the BAA.

∇ GridTest
[1] ⎕USING←,⊂'System,System.dll'
[2] ⎕USING,←⊂'System.IO,mscorlib.dll'
[3] ⎕USING,←⊂'System.Data,system.data.dll'
[4] ⎕USING,←⊂'System.Xml,system.xml.dll'
[5] ⎕USING,←⊂'System.Windows,C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\v3.0\PresentationFramework.dll'
[6] ⎕USING,←⊂'System.Windows,C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\v3.0\PresentationCore.dll'
[7] ⎕USING,←⊂'System.Windows.Input,C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\v3.0\PresentationCore.dll'
[8] ⎕USING,←⊂'System.Windows.Controls'
[9] w←⎕NEW Window
[10] w.(Height Width)←700
[11] dp←⎕NEW DockPanel
[12] SetDT←2010⌶
[13] GetDT←2011⌶
[14] dt←⎕NEW DataTable
[15] x←'First' 'Second' 'Third'{dt.Columns.Add ⍺ ⍵}¨String Int32 Int32
[16] data←100 3⍴((⊂'Patient '),¨⍕¨⍳100),(?100⍴1000),[1.5](?100⍴1000)
[17] SetDT dt data
[18] g←⎕NEW DataGrid
[19] g.Height←600
[20] DockPanel.SetDock g Dock.Top
[21] dv←⎕NEW DataView dt
[22] g.ItemsSource←dv
[23] dp.Children.Add g
[24] w.Content←dp
[25] w.Show
[26] 'Try the following '
[27] 'Move the window so it doesnt overlap the APL session'
[28] 'Then type'
[29] ' 3 UpdRow ''Patient 3.1'' 200 150 '
[30] 'and watch grid'
[31] 'Update the 2nd row of the grid and try'
[32] 'GetRow 2 3 4'
[33] 'Try '
[34] '3 5 UpdRow 2 3⍴''Patient 3'' 25 600 ''Patient 5.01'' 99 100'
User avatar
MikeHughes
 
Posts: 86
Joined: Thu Nov 26, 2009 9:03 am
Location: Market Harborough, Leicestershire, UK

Re: APL/W Grid Object versus WPF DataGrid

Postby MikeHughes on Tue Jul 06, 2010 7:13 am

To get a Grid that displays different data in cells would be possible too with some work. I'm also not sure how efficient it would be so the size of the display may mattter but I think it would be both possible and usable.

If you created a class based on Grid (a WPF layout panel) then each cell can be any wpf object (or collection of wpf objects) which could automticaly resize to fit into their respective grid cells. By providing a couple of custom properties like values and celltypes to the Grid you could mimic the "non tabular" display. This would allow you to mix different data types into the same column or row, different controls like combo boxes/text boxes etc in each column/row.

I think its perhaps non trivial but very doable.
User avatar
MikeHughes
 
Posts: 86
Joined: Thu Nov 26, 2009 9:03 am
Location: Market Harborough, Leicestershire, UK

Re: APL/W Grid Object versus WPF DataGrid

Postby MikeHughes on Tue Jul 06, 2010 7:21 am

Sorry in my haste last night I forgot to add these two functions to make the bottom bit of GridTest work

∇ la UpdRow data
[1] :If 1=⍴⍴data
[2] data←(1,⍴data)⍴data
[3] :EndIf
[4] 2010⌶dt data ⍬(la-1)


∇ r←GetRow la
[1] r←(2011⌶dt)[la;]
User avatar
MikeHughes
 
Posts: 86
Joined: Thu Nov 26, 2009 9:03 am
Location: Market Harborough, Leicestershire, UK

Re: APL/W Grid Object versus WPF DataGrid

Postby MikeHughes on Tue Jul 06, 2010 11:01 am

I apologise - this is very quickly off the top of my head. The start of a general purpose grid with no real restrictions on the contents of each cell.

w←⎕new Window
w.Content←g←DefineGrid 3 4

⍝ DefineGrid is Dynamic xaml - no file - see function below - I couldnt work out how to get one StackPanel to each cell - I only got them all in the first cell with APL but thats where the beauty of xaml comes in - you can mix and match. You should have #.WPF.LoadXaml in Jonathan's ws.

To create cells of a different type - note cell address is by io 0 index into ravelled grid

0 3 {g.Children[⍺].Children.Add ⎕NEW ⍵}¨ComboBox
2 4 {g.Children[⍺].Children.Add ⎕NEW ⍵}¨Button
6 7 8 {g.Children[⍺].Children.Add ⎕NEW ⍵}¨TextBox

6 7 8 {g.Children[⍺].Children[0].Text←⍵}¨'First' 'Second' 'Third' ⍝ Text
2 4 {g.Children[⍺].Children[0].onClick←⍵}¨'Handler1' 'Handler2' ⍝ Button Clicks

text← {g.Children[⍺].Children[0].Text}¨6 7 8
etc etc etc

By adding custom methods and properties you can hide all the complexity above and get what you want as your own WPF control with your own interface so you would replace w with a custom class say BowmanGrid rather than Window.

where DefineGrid is something like (Heights etc need to be made more Auto)

∇ r←DefineGrid size;a;⎕IO
[1] ⎕IO←0
[2] r←⊂'<Grid '
[3] r,←⊂' xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" '
[4] r,←⊂' xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" '
[5] r,←⊂' Name="MCGrid" Height="',(⍕size[0]×45),'" Width=" 400" Background="LightSteelBlue" ShowGridLines="True"> '
[6] r,←⊂' <Grid.ColumnDefinitions>'
[7] r,←size[1]⍴⊂' <ColumnDefinition/>'
[8] r,←⊂' </Grid.ColumnDefinitions>'
[9] r,←⊂' <Grid.RowDefinitions>'
[10] r,←size[0]⍴⊂' <RowDefinition Height=" 45"/>'
[11] r,←⊂' </Grid.RowDefinitions>'
[12] a←(⊂' <StackPanel Grid.Row="'),¨⍕¨size[1]/⍳size[0]
[13] a,¨←(⊂'" Grid.Column="'),¨⍕¨(×/size)⍴⍳size[1]
[14] r,←a,¨⊂'"/>'
[15] r,←⊂'</Grid>'
[16] r←#.WPF.LoadXaml⊃,/r
User avatar
MikeHughes
 
Posts: 86
Joined: Thu Nov 26, 2009 9:03 am
Location: Market Harborough, Leicestershire, UK

Re: APL/W Grid Object versus WPF DataGrid

Postby Dick Bowman on Tue Jul 06, 2010 11:26 am

Thanks for the replies - I'd composed a response, but then lost it.

Mike, you have hit the nail on my head - that is precisely the direction I was pondering.

XAML in files seems too limiting (for my purposes) - I've found myself using VB to make myself a quickie then tweaking by hand (and using a tool call Kaxaml for a visual confirmation) - realising that I'm putting off the day when I bring it back within APL.

I need to get my hands on the Nathan WPF book I think - when the new edition appears in a few weeks.

I shall experiment - slowlyish - and post back any further enlightenment.
Visit http://apl.dickbowman.com to read more from Dick Bowman
User avatar
Dick Bowman
 
Posts: 235
Joined: Thu Jun 18, 2009 4:55 pm

Re: APL/W Grid Object versus WPF DataGrid

Postby MikeHughes on Tue Jul 06, 2010 11:42 am

Dick,

A good way to massage xaml files is to use []xml. This way you can design GUIs or part GUIs with APL handlers in the xaml on file using your favourite designer. Then if all the event functions start with ∇ (a trick Morten came up with) they can be removed before loading and reapplied afterwards. Other variable parts of the xaml can be placed in delimiters to be parsed and doctored with APL prior to LoadXaml.

The data/element binding syntax {} markup in xaml is really useful and sometimes cumbersome in code, xaml is worth understanding just for this.

I find an xaml file containing my own markup, parsed/doctored after reading but before loading and then modified afterwards is very powerful.

This way you can work with the strengths of both xaml and APL.

The book is worth having but there are also some great tutorials out on the web.
User avatar
MikeHughes
 
Posts: 86
Joined: Thu Nov 26, 2009 9:03 am
Location: Market Harborough, Leicestershire, UK

Re: APL/W Grid Object versus WPF DataGrid

Postby Dick Bowman on Tue Jul 06, 2010 2:17 pm

I will get there - it will just take a while.

Would you like to be more specific about "great" tutorials - I know of the one that Simon Marsden mentioned in the APL Wiki (Christian Moser's WPF Tutorial), where does it sit on the rubbish-to-excellent spectrum?
Visit http://apl.dickbowman.com to read more from Dick Bowman
User avatar
Dick Bowman
 
Posts: 235
Joined: Thu Jun 18, 2009 4:55 pm

Next

Return to Microsoft.NET

Who is online

Users browsing this forum: No registered users and 1 guest