Code
There are 15 entries for the tag
Code
So it turns out that the WinForms TreeView control doesn't support binding anything but a Text property to its nodes. This is a pretty lame oversight given what the control is used for (displaying a set of hierarchical data) and we had a need to find a way to bind complex types to the thing. Were this a few months ago we would have had to subclass the control, take in Objects, and do awkward things to make it happen. But now that .net 3.5 is my bff, a quick combination of extension methods and generics will do...
Last night I had cause to measure the rendered dimensions of a string at a given font and width. Without going to much into the why, let's just say if you need to do this you're either doing custom text rendering, or, in my case, positioning report elements relatively in a report suite that doesn't update Control.Height except in some magical layout land that you can't figure out how to access. To get around the problem, I came up with this: private int MeasureStringHeight(int width, string textToMeasure, Font font){ Bitmap bmp = new Bitmap(1,1); Graphics g = Graphics.FromImage(bmp); SizeF bounds...
So like many of you I use del.icio.us to manage my bookmarks. My biggest problem is tag creep. Depending on my state of mind/mood I end up with a lot of useless/duplicated tags. This is particularly the case when I didn't have the Firefox plugin that autocompletes existing tags as you type, or when I click the suggested community tags for a given entry when I have an existing tag that would have fit but maybe was worded differently. So for a long while I've been wanting to put together a simple app that would bulk rename/merge tags so I could...
Previously we've looked at using Word Interop for creating dynamic documents, ranging from the simple, to the more in-depth, methods of working with Word from C#. Check out Part 1, Part 2, and Part 3 to learn about working with bookmarks, ranges, images, and other tidbits. Barring any more specific requests for information this will be the final installment, so I can get this stuff out of my brain and forget it ever happened.
Tables are a great way to add both visual structure and navigability to your documents. Creating a table structure in your templates can make you less reliant...
I know I said I'd talk about tables next, but I'll do those later. For now I want to discuss just a few handy little things I picked up along the way.
Putting Images in a Word Doc
Someone asked about this in the comments to my last post. I don't know that this is the *best* way to put images in the document, but it's the easiest way I've found, with the least intrusive amount of code:
//get Range for your insert point, like via bookmark Object bookmark = "InsertRange";Range insertRange = wordDocument.Bookmarks.get_Item(ref bookmark).Range;//get a System.Drawing.Image //obviously you could get the image...
In the last post about interop I gave you some basic code and techniques to do some really basic word document interaction. In this one, I'm going to go beyond that and get into some more advanced document interaction. I learned most of this because someone who no longer works for me locked us into Word as our "reporting platform", but at the 11th hour I realized the reports weren't really all that...implemented....and I had to basically start from scratch. I was displeased. Fair warning - if you find yourself needing this information, I beg you to find another way to do...
In my last project I had to do A LOT of Word Interop. Everything from data-heavy reports to quick documents exist in this system. Let me start by saying if you can find a way for to do what you want WITHOUT using Word Interop....do it. It's such a pain in the ass if you want to do anything non-trivial.
Some things word interop really shines for is allowing you to preformat a document and just "fill in the blanks" with some data. This is great if you're doing something like Packing Slips, cover sheets, and other simple documents.
Basic Word Interop
Let's...
Last month Jeff posted this blog entry about Properties vs. Public Variables and I mostly agreed with his thoughts, although I’m usually a use-a-property-to-encapsulate-a-variable person just for appearances. I wish I had seen the update he put in the entry it would have saved me a few minutes of annoyance.
So I just stumbled across this lame rule today even though I’ve been databinding custom business objects for a long time, so I thought I would make a post just in case someone else runs into it and can’t figure out the issue right away.
Basically, I wanted a quick “data view” representation...
Good call to Marty in the comments of my last post, who basically hit the nail on the head. I had been content to leave it alone and just go about setting them in that order, but something he said struck me as odd. He said (regarding setting the DisplayMember) “ which it is by default, but you also explicitly declared it that as well”. And that got me thinking about documented expected behavior, and actuality.
His contention is that basically when you Set ValueMember if DisplayMember is empty then replace with value member. Minus some syntactic sugar and refactoring, he’s...
Discovered something interesting and annoying today…pardon me if you’ve already heard this one.
In C# 2.0 if you bind a List<BusinessObject> to a System.Windows.Forms.ComboBox you can set the ValueMember and the DisplayMember to set which properties of your business object will be the “value” and which will be the “display” text. Simple enough.
After playing around a bit, I “discovered” that if you set DisplayMember = “”; (empty string) then it will use the ToString() of the bound object. I say “discovered” because if I had looked on MSDN I would have seen that…but I didn’t, and I found out by accident,...
Don’t ridicule.
While continuing to get my life in order, I plan to start Getting Things Done. Maybe not to the letter, but certianly to the spirit.
Anyway, I often find myself making to-do lists, or jotting random stuff down, and usually I’ll do a Start|Run notepad and jot a few line items. By the end of the day I have several whatever.txt files on my desktop, and they build up. Someone out there please confirm if you do the same? Tell me I’m not an aberration. I need validation!
Whoa. Ok. Back to reality. So in addition to all the notepad files,...
Continuing my efforts to educate my team on the new features of 2.0, here’s what I had to say about Partial Types. (Maybe I don’t “get” partial types…they seem more like they would be sources of confusion than actually useful…)
One of the first things you will likely notice, when you go to create a new form (win or web) is that the “code behind” is different. Incomplete. Or, put in the manner of the Talking Heads:
And you may find yourself, creating a new WinForm;
And you may find yourself, looking in the Code-Behind
And you may find definitions, in another part of...
As I mentioned previously I’m educating my team on the new 2005/2.0 stuff, and extending that here. This is not new information, but as they say on TV during the summer, “if you haven’t seen it, it’s new to you”. (and if it’s not new to you, and I get it totally wrong, please tell me. I’m still learning this stuff too.)
One of the new features of C# in 2.0 is what’s called “Generics”. What is a generic? Essentially it boils down to generalization in design.
Think about a collection of some object. In a structure such as a Linked List. Very...
So I got bored today while I was waiting for Sam to get here and open his presents. Registered for del.icio.us. Figured, rather than do a bunch of linkblogging here, when I primarily just want to save links, I could del.icio.us them. Then I decided since I don’t really web browse anymore, I should make an RSSBandit plugin. Get it here. Unzip to the Plugins directory of RSSBandit, change the delicious.xml file to have your del.icio.us user name, launch RSSBandit, and you’re good to go.
Should work in other IBlogExtension supporting aggregators…but I’m not going to test it…so let me know.
If...
So some of you may have read about my annoyance a few days ago with RSSBandit bagging all my items marked for followup. Yes, totally my fault for the procrastinating.
So anyway, I decided tonight to give a try at creating a plugin for RSSBandit. It was about the easiest code I've ever written, mostly because I wrote basically none of it! I used the OneNote Managed API from Donovan, and of course I implemented the IBlogExtension interface after reading through the excellent tutorial from you've been haacked. All in all, about 10 minutes to learn, write, test.
The plugin allows you...