Scott Hanselman

How do I automatically size (autosize) Columns in a WinForms DataGrid?

June 17, 2004 Comment on this post [19] Posted in Programming
Sponsored By

Apparently this is, like, the problem for the ages or something, but noone on this planet has come up with a way to automatically size the columns in a DataGrid.  Sure, there's all sorts of pyscho ways that involve measuring the length of strings in DataSets with the Graphics context, yada yada.  But, since I'm binding strongly-typed Object Collections to DataGrids in WinForm apps, that doesn't work for me (and it's a little over the top, IMHO).

So, I thought about it like this:

  • If you double click on the little splitter between columns they will autosize.
  • Therefore, the code to autosize has been written for me; no need to measure strings, etc.
  • How do I force a double click? No, wait, wrongheadedness, how do I call whatever THEY call when a double click happens?
  • So, I reflectored into DataGrid.OnMouseDown and saw their custom HitTest calls a private ColAutoResize.  Ah, bingo.

If you're going to 'sin' do it with style - do it with Reflection.

private void dgLogging_DataSourceChanged(object sender, System.EventArgs e)
        {
            try
            {
                Type t = dgLogging.GetType();
                MethodInfo m = t.GetMethod("ColAutoResize",BindingFlags.NonPublic);

                for (int i = dgLogging.FirstVisibleColumn; (i < dgLogging.VisibleColumnCount); i++)
                {
                    m.Invoke(dgLogging, new object[]{i});
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Trace.Write("Failed Resizing Columns: " + ex.ToString());
            }
        }

(Thanks to Patrick Cauldwell for his help)

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook bluesky subscribe
About   Newsletter
Hosting By
Hosted on Linux using .NET in an Azure App Service

RSS Feed to dasBlog Content Converter

June 17, 2004 Comment on this post [2] Posted in ASP.NET | DasBlog | Nant | XML | Tools
Sponsored By

Greg Hughes once had a LiveJournal Blog and the only remnant of his blog was an RSS Feed/Archive.  Now that he runs dasBlog he wanted to move his old content foward into dasBlog.  So, we googled a bit and couldn't find a tool that would take an RSS (2.0) feed as input and put the entries into dasBlog.

So we made one over lunch, and here it is: RSStoDasBlog.zip (219.29 KB)

RSStoDasBlog.exe MyRssFile.xml "C:\documents and settings\whatever\dasblog\content"

Use it like this by pointing it to the RSS file and your (local) dasBlog content folder.  It will create all the needed dayentry.xml files for you to upload to your remote blog.  It will also (I think) take an http:// url to an RSS file and could be used to (possible as a service?) steal RSS and mirror them in dasBlog.  Thanks to Jerry (Chris) Maguire's RSS Framework that showed up first in Google and saved me the time of running XSD.exe on an RSS XML schema. Apparently he has even newer stuff on his site.  It's got a few more moving parts than I think it needs to, but it did the job with a few changes that I marked with my initials; SDH.

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook bluesky subscribe
About   Newsletter
Hosting By
Hosted on Linux using .NET in an Azure App Service

Windows XPSP2 RC2 on the TabletPC doesn't work in FireFox 0.9? *GASP*

June 16, 2004 Comment on this post [4] Posted in Musings
Sponsored By

Apparently the TIP (TabletPC Input Panel) in Windows XP SP2 RC2 doesn't detect the TextBoxes in FireFox 0.9?  Is anyone else seeing this egregious behavior?

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook bluesky subscribe
About   Newsletter
Hosting By
Hosted on Linux using .NET in an Azure App Service

My upcoming speaking schedule

June 16, 2004 Comment on this post [1] Posted in ASP.NET | Web Services | Speaking
Sponsored By

Before I forget, here's my upcoming Speaking Schedule, which currently consists of Users Groups:

  • Bay.NET - chillin' in SFO with Web Services.  If you're in San Francisco or Oakland or Los Gatos or any points in between, come hang with us.  Spread the word and rush the stage. 
  • South Sound Users Group - TOPIC TBD, but it will undoubtably be fun, as I will drive up to Olympia to talk to my fellow Northwesterners.
  • South Colorado.NET Users Group - Probably a .NET Internals talk, where we'll start at LoadLibrary(), move past CoCreateInstance and end up at GetType() and Assembly.Load().  Very intense and upbeat talk that's mucho funno.
    • When: Tuesday, 10/5/2004 at 5:30 PM-ish
      Where: Probably at NxTrend in Colorado Springs, CO

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook bluesky subscribe
About   Newsletter
Hosting By
Hosted on Linux using .NET in an Azure App Service

Not only does Firefox rock, but Thunderbird rocks as well

June 16, 2004 Comment on this post [4] Posted in Javascript
Sponsored By

The irony of this is not lost on me, as I introduced a large number of my friends and colleagues to the Joy of using Firefox (then Firebird).

In the many comments that were in the Spam Thread were suggestions that I use SpamBayes with Outlook and/or Thunderbird.

(It's worth noting that that original screenshot was on my little TabletPC, and that I DO in fact run Outlook 2003 in my real life.)

However, as IT Manager for my Family, I have to maintain the boxes of various cousins, great-uncles, wife, brother, etc.  So, God help me, they've been running Outlook Express.

Why is the Fam so behind?  Well, I can't give them all my MSDN Office Licenses, that wouldn't be "Right."  But, largely I have been moving them to free software so I can sleep at night (and they can eat ;) ).  Dad and Mom run http://www.OpenOffice.org and FireFox today.

I've been avoiding Thunderbird just because I'm REALLY not a fan of the whole "Mozilla" Suite.  Mind you, it's the SUITE, not the Apps.  But back in the day I tried the Mozilla Mail, and it just smacked too much of Netscape early on and I guess I got turned off.

But, I installed Thunderbird and I feel so strongly about it that I must reuse a metaphor - forgive me.

Comparing Thunderbird to Outlook Express is the difference between shooting a bullet...and throwing one.

I'm VERY impressed.  As I looked around for features within the menus, I found everything I was looking for.  Here's what I was most impressed with:

  • A Junk Email Filter that LEARNS.
  • VERY Advanved Rules/Filtering Engine
  • The ability to run in "Vertical" Preview Mode
  • Turning off of both JavaScript and inline external Images
  • Create Rule/Filter from Example Email
  • VERY Flexible Font Sizing choices, including a "Minimum Font Size" option (Very nice for Accessibility.  Even with Bionic Eyes, I still like a big font.)
  • Skinnable with Themes
  • Totally different way of thinking about addressing (a grid, rather than To:, CC:, BCC: boxes)
  • Popup "Toast" New-Email indicator

I suggest that if you have any relatives running Outlook Express, that you move them to Thunderbird tomorrow.  Thanks Readers, for forcing me to take a second look at this piece of software!

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook bluesky subscribe
About   Newsletter
Hosting By
Hosted on Linux using .NET in an Azure App Service

Disclaimer: The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.