Click here to Skip to main content
15,923,689 members
Home / Discussions / C#
   

C#

 
AnswerRe: It must be >= 0 and < the PageCount Pin
Colin Angus Mackay14-Jul-06 21:56
Colin Angus Mackay14-Jul-06 21:56 
AnswerRe: It must be >= 0 and < the PageCount Pin
Paul Conrad15-Jul-06 10:54
professionalPaul Conrad15-Jul-06 10:54 
QuestionRead location in .lnk (shortcut) file Pin
StyrofoamSUV14-Jul-06 18:56
StyrofoamSUV14-Jul-06 18:56 
AnswerRe: Read location in .lnk (shortcut) file Pin
kasik15-Jul-06 5:15
kasik15-Jul-06 5:15 
GeneralRe: Read location in .lnk (shortcut) file Pin
StyrofoamSUV15-Jul-06 6:46
StyrofoamSUV15-Jul-06 6:46 
QuestionHow can I display a .mht file on a webBrwoser control? Pin
AngryC14-Jul-06 15:49
AngryC14-Jul-06 15:49 
AnswerRe: How can I display a .mht file on a webBrwoser control? Pin
Andrew Lygin14-Jul-06 19:20
Andrew Lygin14-Jul-06 19:20 
QuestionStringCollection Property Design Time Editing Pin
Loophole14-Jul-06 13:10
Loophole14-Jul-06 13:10 
I have a custom control that has a StringCollection property:
private StringCollection _images = new StringCollection();

[Category("_Hotspot"),
TypeConverter(typeof(StringCollectionConverter)),
EditorAttribute("System.Windows.Forms.Design.StringCollectionEditor, System.Design", "System.Drawing.Design.UITypeEditor, System.Drawing")]
public StringCollection Images
{
	get {return _images;}
	set {_images = value;}
}

I want to be able to edit it at design time, so I wrote a type converter to translate it into a string and back in the attribute:
public class StringCollectionConverter : TypeConverter
{
	public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
	{
		if (sourceType == typeof(string))
			return true;
		else
			return base.CanConvertFrom(context, sourceType);
	}

	public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
	{
		if (destinationType == typeof(StringCollection))
			return true;
		else if (destinationType == typeof(InstanceDescriptor))
			return true;
		else
			return base.CanConvertTo(context, destinationType);
	}

	public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
	{
		if (value is string)
		{
			string[] v = ((string)value).Split(new char[] {','});
			StringCollection stringList = new StringCollection();
			for (int i=0; i<v.Length; i++)
			{
				stringList.Add(v[i]);
			}
			return stringList;
		}
		
		return base.ConvertFrom(context, culture, value);
	}

	public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType)
	{
		StringCollection stringList;
		
		if (destinationType == typeof(string))
		{
			stringList = (StringCollection)value;
			string result = "";
			for (int i=0; i<stringList.Count; i++)
			{
				result += stringList[i];
				if (i < stringList.Count - 1)
					result += ",";
			}
			return result;
		}
		else if (destinationType == typeof(InstanceDescriptor) && value is StringCollection)
		{
			stringList = (StringCollection)value;
			ConstructorInfo ctor = typeof(StringCollection).GetConstructor(new Type[] {});
			if (ctor != null)
				return new InstanceDescriptor(ctor, new object[] {});
		}
		
		return base.ConvertTo(context, culture, value, destinationType);
	}
}

I'm able to click the elipse in the editor, bring up the string collection editor, and enter strings. The strings are written out properly as a comma delimited list in the attribute of the control, but when I run the app, those values are never initialized into the string collection at runtime.

This seems like a lot of work to have a simple collection of strings as a property. Does anyone know how to make this work? I've been searching the web trying to figure this out for days. Lots of people ask about it, but no-one really seems to have the answer. Thanks.

Jason
AnswerRe: StringCollection Property Design Time Editing Pin
Robert Rohde15-Jul-06 11:13
Robert Rohde15-Jul-06 11:13 
GeneralRe: StringCollection Property Design Time Editing Pin
Loophole17-Jul-06 6:12
Loophole17-Jul-06 6:12 
GeneralRe: StringCollection Property Design Time Editing Pin
Robert Rohde17-Jul-06 7:14
Robert Rohde17-Jul-06 7:14 
GeneralRe: StringCollection Property Design Time Editing [modified] Pin
Loophole20-Jul-06 7:11
Loophole20-Jul-06 7:11 
GeneralRe: StringCollection Property Design Time Editing Pin
Robert Rohde20-Jul-06 10:37
Robert Rohde20-Jul-06 10:37 
QuestionLaunch other program in mdi? Pin
Toreddo14-Jul-06 11:59
Toreddo14-Jul-06 11:59 
AnswerRe: Launch other program in mdi? Pin
Dave Kreskowiak14-Jul-06 16:33
mveDave Kreskowiak14-Jul-06 16:33 
GeneralRe: Launch other program in mdi? Pin
Toreddo14-Jul-06 20:06
Toreddo14-Jul-06 20:06 
GeneralRe: Launch other program in mdi? Pin
Colin Angus Mackay14-Jul-06 21:57
Colin Angus Mackay14-Jul-06 21:57 
GeneralRe: Launch other program in mdi? Pin
Toreddo15-Jul-06 2:26
Toreddo15-Jul-06 2:26 
AnswerRe: Launch other program in mdi? Pin
stancrm14-Jul-06 23:16
stancrm14-Jul-06 23:16 
GeneralRe: Launch other program in mdi? Pin
Toreddo15-Jul-06 2:28
Toreddo15-Jul-06 2:28 
AnswerRe: Launch other program in mdi? Pin
Eran Aharonovich16-Jul-06 3:47
Eran Aharonovich16-Jul-06 3:47 
QuestionSession Variables IIS Pin
oskardiazdeleon14-Jul-06 11:01
oskardiazdeleon14-Jul-06 11:01 
AnswerRe: Session Variables IIS Pin
oskardiazdeleon23-Jul-06 12:59
oskardiazdeleon23-Jul-06 12:59 
QuestionIssues with SetNotificationPositions Pin
flend14-Jul-06 10:03
flend14-Jul-06 10:03 
Questionhow to get largest element from list Pin
_ra14-Jul-06 9:35
_ra14-Jul-06 9:35 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.