$theTitle=wp_title(" - ", false); if($theTitle != "") { ?>
dabbling, frivolling, idling, loafing, loitering, playing and procrastinating
24 Apr // php the_time('Y') ?>
Not that the trend around here are DataGridView’s or anything, it just seems that the small tid bits of information about things people I expect do quite often with them are always hidden away on a dead server most of the time.
I needed to have a column auto sorted when the application loaded, now this can be done several ways, but in my instance I do not have a DataSource as I am populating the grid manually. This is perhaps the only way to specify a sort on a manually populated table (short of clicking the header yourself)…
dgv.Sort(dgv.Columns.GetLastColumn( DataGridViewElementStates.Visible, DataGridViewElementStates.None), ListSortDirection.Descending);
Luckily for me this code is quite nice on the one line, however, if the column you want auto sorting isn’t either the first or last one, your going to have to go through each column until you have found the one you want.
23 Apr // php the_time('Y') ?>
Again, another nugget of information I hunted around for and just couldn’t find. To alternate row styles, or more specifically, background colour…
dgv.RowsDefaultCellStyle.BackColor = Color.White;
Technically that should already be set from when you added the grid view, but I do it just to make sure. So now that the default is set, we can specify the alternate colour…
dgv.AlternatingRowsDefaultCellStyle.BackColor = Color.Gray;
If you don’t want to use the standard set colours, you can always specify your own…
dgv.AlternatingRowsDefaultCellStyle.BackColor = Color.FromArgb(240, 240, 240);
22 Apr // php the_time('Y') ?>
This annoyed me somewhat as I couldn’t find any good documented examples of how to use resourced icons in a C# project. So, after a few google searches the answer is…
Properties.Resources.yourResourceNameHere
or
Form1.Properties.Resources.yourResourceNameHere
Yup, its that simple, of course though this can get more complex. In my project I wanted to put some icons into an ImageList, but I wanted to put all my embedded icons into it and then assign them keys so that other parts of my code could find them. (This could obviously be improved, especially where it checks to see what type of resource it is)
foreach (DictionaryEntry resourceEntry in Properties.Resources.ResourceManager.GetResourceSet(
System.Globalization.CultureInfo.CurrentUICulture, true, true));
{
if (resourceEntry.Value.GetType().ToString() == “System.Drawing.Icon”)
{
imageList.Images.Add((System.Drawing.Icon) Properties.Resources.ResourceManager.GetObject( resourceEntry.Key.ToString()));
imageList.Images.SetKeyName(imageList.Images.Count – 1, resourceEntry.Key.ToString());
}
}
It looks a bit messy here, but it looks much better in a proper editor