Ok, so binding a grid to a list is easy, but what if you want changes in the list to be shown in the grid?
Well actually, it turns out, this is easy too - just not obvious.
Instead of using System.Collections.Generic.List<T>
use System.ComponentModel.BindingList<T>
It's exactly the same in all important regards, but it has the methods necessary for the grid to know that the list has changed
Easy huh!
A bit about the stuff I've done
Thursday, 19 January 2012
Friday, 13 January 2012
Editing xml in vim
Yes, I use vim!
And large html, xml and xsl documents can be frustrating so here are a few things I sussed out today to make it easier:
N.B. when folding it folds everything at that level, not everything that is a child.
In other words if you had this document:
and you press zc when the cursor is on the line with node1 then rather than hiding node1a and node1b like you might expect - it hides node1 and node2 (as well as their children)
And large html, xml and xsl documents can be frustrating so here are a few things I sussed out today to make it easier:
- None of the commandline tools I could find were capable of cleanly formatting an xml document and putting comments in the correct alignment. All of them put the comments with no indentation.
Some of you may prefer this but it stosp the following tips from working correctly in vim
So I wrote a quick 5 min tool to do this, and here it is.
Extract that archive somewhere into your path and then simplycat unformatted.xml | xmltidy > formatted.xml
easy :)
N.B. You'll need to have mono installed. - Next I've assigned this new tool to an easy key in vim
In your .vimrc file enter the following::map <F2> :1,$!xmltidy<Enter>
You can use any key you like of course - Next I enabled code-folding
Now there are plenty of posts out on the web about getting code folding with xml to work however I had issues with all of them.
What I found to work was to enable folding by indentation (hence why comments have to be in the correct alignment).
These 2 lines of vimrc sorted that out for me:
au FileType htm,html,xml.xsl,xslt exe ":set foldmethod=indent"
au BufNewFile,BufRead *.htm,*.html,*.xml,*.xsl,*.xslt exe ":set shiftwidth=2"
N.B. I have my tabstop set to 2 so that pressing the tabkey indents the line by 2 columns instead of the usual - Finally; if, like me, you don't like that ugly banner on the code folding lines then you'll want to change the colours with this line:
:highlight Folded ctermbg=black
N.B. when folding it folds everything at that level, not everything that is a child.
In other words if you had this document:
<xml>
<node1>
<node1a/>
<node1b/>
</node1>
<node2>
<node2a/>
<node2b/>
</node2>
</xml>
and you press zc when the cursor is on the line with node1 then rather than hiding node1a and node1b like you might expect - it hides node1 and node2 (as well as their children)
Distinct in XSL
So I frequently have a need to do this but I can never remember how, so I figure why not use my shiny new blog and write about it here!
The problem:
The xml:
the result:
The solution:
You can use the
This function is part of xsl so you don't need any funky includes, but it means you can't use it from XPath (e.g. from C#'s SelectNodes() method)
And that's it!
Let's break it down
The problem:
- You have some node list which contains many, many items.
- You want to group items based on part of their content
- You want to do it in xsl
The xml:
<phrases>
<node type="Greeting">Hello</node>
<node type="Farewell">Goodbye</node>
<node type="Greeting">Hi</node>
<node type="Greeting">Howdy</node>
<node type="Farewell">See you later</node>
</phrases>
the result:
Greeting
Farewell
The solution:
You can use the
generate-id()
function.This function is part of xsl so you don't need any funky includes, but it means you can't use it from XPath (e.g. from C#'s SelectNodes() method)
<xsl:if test="generate-id(.) = generate-id(../node[@type=current()/@type])>
<xsl:value-of select="."/>
</xsl:if>
And that's it!
Let's break it down
generate-id(.)
Does exactly what you might expect i.e. it generates a unique ID which represents the current node. Calling generate-id on the same node twice will return the same id.../node[@type=current()/@type]
This bit gets all the other nodes which have the same value based on the key we are grouping by (in this case
Visit my webites
As well as this blog I have 2 main websites currently.
http://dev.dj-djl.com/radioswitcher.aspx
When this project goes live I will probably give it its own domain name
- My DJing website; where you can download plenty of my mixes:
http://www.dj-djl.com
- My development website which lists the personal software projects I have developed
http://dev.dj-djl.com
http://dev.dj-djl.com/radioswitcher.aspx
When this project goes live I will probably give it its own domain name
Welcome to my blog
I've just created this blog today so bare with me while the content slowly builds!
I guess the idea behind this blog is to share some of the cool things I've done or discovered in the development world.
Hopefully someone somewhere will find it useful!
I guess the idea behind this blog is to share some of the cool things I've done or discovered in the development world.
Hopefully someone somewhere will find it useful!
Subscribe to:
Posts (Atom)