Archive for October, 2008
c# Property Grid – Getting a combo box
by brian on Oct.31, 2008, under Uncategorized
You’d think getting a combox display into the property grid would be really simple to do since it’s used everywhere in Visual Studio 2008. And although it isn’t horrible it isn’t exactly straight forward. I found a couple of dead-ends, poorly explained, or difficult to find the pith of examples. Finally I ran across this one at http://gaaton.blogspot.com/ It’s nice and concise, easy to understand, and easy to adapt. I’m going to put in my sample which essentially taken from gaaton.
internal class ProtcolConverter : StringConverter
{
public override bool
GetStandardValuesSupported(
ITypeDescriptorContext context)
{
//True - means show a Combobox
//and False for show a Modal
return true;
}
public override bool
GetStandardValuesExclusive(
ITypeDescriptorContext context)
{
//False - a option to edit values
//and True - set values to state readonly
return true;
}
public override StandardValuesCollection
GetStandardValues(
ITypeDescriptorContext context)
{
return new StandardValuesCollection(
new string[] { "net.tcp", "http" });
}
}
And finally the we need to attach the string converter to the property by the following.
[TypeConverter(typeof(ProtcolConverter))]
public string ServiceProtocol
{
get { return MediaServiceConfig.WCFProtocol; }
set { MediaServiceConfig.WCFProtocol = value; }
}
Enjoy.
MS SQL tricks for uniqueidentifers or Guid and date time.
by brian on Oct.29, 2008, under mmsql
In MS SQL Server 2005 the following code is how to get a new uniqueidentifier, and the current date and time.
SELECT newid(),getdate()
Produces these results.
------------------------------------ ----------------------- 125700F3-8FB8-496F-8EA4-35D9CB9E8415 2008-10-29 13:09:54.557 (1 row(s) affected)
c# linq to sql string comparisons
by brian on Oct.27, 2008, under .NET, c#, coding, linq, sql
There are four different string comparisons for handling string fields with linq to sql. They are as follows:
The exact macth
DataContext dc = new DataContext(...) var results = from row in dc.table where row.string_column == "Exact Match" select row;
Begins With:
DataContext dc = new DataContext(...)
var results =
from row in dc.table
where row.string_column.StartsWith("Ex")
select row;
produces an sql match string “Ex%”
Contains
DataContext dc = new DataContext(...)
var results =
from row in dc.table
where row.string_column.Contains("Ex")
select row;
Which is equivalent to “%Ex%”
Ends With
DataContext dc = new DataContext(...)
var results =
from row in dc.table
where row.string_column.EndsWith("Ex")
select row;
Which is equivalent to “%Ex”
