Click here to Skip to main content
15,915,807 members
Home / Discussions / C#
   

C#

 
QuestionWhy is the file used by another process? Pin
Libor Tinka27-Dec-05 12:29
Libor Tinka27-Dec-05 12:29 
AnswerRe: Why is the file used by another process? Pin
peshkunta27-Dec-05 19:16
peshkunta27-Dec-05 19:16 
AnswerRe: Why is the file used by another process? Pin
Dave Kreskowiak28-Dec-05 5:33
mveDave Kreskowiak28-Dec-05 5:33 
GeneralRe: Why is the file used by another process? Pin
Libor Tinka29-Dec-05 1:11
Libor Tinka29-Dec-05 1:11 
QuestionWebBrowser Control Encoding (.NET 2.0) Pin
Matt Newman27-Dec-05 12:09
Matt Newman27-Dec-05 12:09 
QuestionMaking instance of object availble to script Pin
dahlman27-Dec-05 12:02
dahlman27-Dec-05 12:02 
AnswerRe: Making instance of object availble to script Pin
dahlman28-Dec-05 11:28
dahlman28-Dec-05 11:28 
QuestionTypeConverter question Pin
Jamie Nordmeyer27-Dec-05 11:31
Jamie Nordmeyer27-Dec-05 11:31 
I'm sure I'll kick myself when I see the answer to this, but I'm having a complete brain fart at the moment. I have a custom control that I'm writing for an ASP.NET custom control (it's here because I think the question is generic to both ASP.NET and Windows Forms). What I want is for my property editor to show a drop down with the names of all the controls on my page. I know how to retrieve the ID's of all my controls, I just can't get the TypeConvertor to work properly. Here's my TypeConverter derived class:

<br />
public class RequiredControlListTypeConverter : TypeConverter<br />
	{<br />
		public override bool GetStandardValuesSupported(ITypeDescriptorContext context)<br />
		{<br />
			return true;<br />
		}<br />
<br />
		public override bool GetStandardValuesExclusive(ITypeDescriptorContext context)<br />
		{<br />
			return true;<br />
		}<br />
<br />
		public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)<br />
		{<br />
			if (destinationType == typeof(string))<br />
				return true;<br />
			return base.CanConvertTo (context, destinationType);<br />
		}<br />
<br />
		public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType)<br />
		{<br />
			if (destinationType == typeof(string) && value is string)<br />
				return Convert.ToString(value);<br />
			return base.ConvertTo (context, culture, value, destinationType);<br />
		}<br />
<br />
		public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)<br />
		{<br />
			if (sourceType == typeof(string))<br />
				return true;<br />
			return base.CanConvertFrom (context, sourceType);<br />
		}<br />
<br />
		public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)<br />
		{<br />
			if (value is string)<br />
			{<br />
				IDesignerHost host = (IDesignerHost)context.GetService(typeof(IDesignerHost));<br />
				Page page = (Page)host.RootComponent;<br />
				return page.FindControl((string)value);<br />
			}<br />
<br />
			return base.ConvertFrom(context, culture, value);<br />
		}<br />
<br />
<br />
		public override System.ComponentModel.TypeConverter.StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)<br />
		{<br />
			IDesignerHost host = (IDesignerHost)context.GetService(typeof(IDesignerHost));<br />
			Page page = (Page)host.RootComponent;<br />
			StringCollection ctrlIDs = new StringCollection();<br />
			FindControls(page.Controls, ctrlIDs);<br />
			return new StandardValuesCollection(ctrlIDs);<br />
		}<br />
<br />
		private void FindControls(ControlCollection ctrls, StringCollection ctrlIDs)<br />
		{<br />
			foreach(Control ctrl in ctrls)<br />
			{<br />
				if (ctrl.HasControls())<br />
					FindControls(ctrl.Controls, ctrlIDs);<br />
				ctrlIDs.Add(ctrl.UniqueID);<br />
			}<br />
		}<br />
	}<br />


This TypeConverter is used on a property whose type is System.Web.UI.Control. The problem I'm having is that when I go to choose a control, I get the controls type (System.Web.UI.WebControls.TextBox, for example), not its ID. Any ideas?

Thanks in advance.

Kyosa Jamie Nordmeyer - Taekwondo Yi (2nd) Dan
Portland, Oregon, USA


-- modified at 17:32 Tuesday 27th December, 2005
AnswerRe: TypeConverter question Pin
minhpc_bk27-Dec-05 16:05
minhpc_bk27-Dec-05 16:05 
GeneralRe: TypeConverter question Pin
Jamie Nordmeyer28-Dec-05 4:35
Jamie Nordmeyer28-Dec-05 4:35 
AnswerRe: TypeConverter question Pin
leppie27-Dec-05 18:42
leppie27-Dec-05 18:42 
GeneralRe: TypeConverter question Pin
Jamie Nordmeyer28-Dec-05 4:38
Jamie Nordmeyer28-Dec-05 4:38 
AnswerRe: TypeConverter question Pin
Jamie Nordmeyer29-Dec-05 9:44
Jamie Nordmeyer29-Dec-05 9:44 
QuestionHow to show GridView even when no data Pin
Genbox27-Dec-05 10:00
Genbox27-Dec-05 10:00 
QuestionSQLCommandBuilder problem Pin
HolyGrandFather27-Dec-05 9:24
HolyGrandFather27-Dec-05 9:24 
AnswerRe: SQLCommandBuilder problem Pin
Gokulan Venattil27-Dec-05 21:55
Gokulan Venattil27-Dec-05 21:55 
GeneralRe: SQLCommandBuilder problem Pin
HolyGrandFather27-Dec-05 22:58
HolyGrandFather27-Dec-05 22:58 
QuestionTaskBar hide/show???? Pin
Small Rat27-Dec-05 8:14
Small Rat27-Dec-05 8:14 
AnswerRe: TaskBar hide/show???? Pin
Curtis Schlak.27-Dec-05 8:34
Curtis Schlak.27-Dec-05 8:34 
QuestionVS 2005 Case-sensitive Search Pin
Kevin McFarlane27-Dec-05 8:11
Kevin McFarlane27-Dec-05 8:11 
QuestionAnyone using PowerCollections? Pin
Kevin McFarlane27-Dec-05 8:10
Kevin McFarlane27-Dec-05 8:10 
QuestionWhat is the proper way to embed an MS Access DB into an application? Pin
bc111827-Dec-05 4:54
bc111827-Dec-05 4:54 
AnswerRe: What is the proper way to embed an MS Access DB into an application? Pin
VenkataRamana.Gali27-Dec-05 7:41
VenkataRamana.Gali27-Dec-05 7:41 
Questionloop through opened word document c# win app Pin
fady_sayegh27-Dec-05 4:53
fady_sayegh27-Dec-05 4:53 
AnswerRe: loop through opened word document c# win app Pin
Gokulan Venattil27-Dec-05 20:00
Gokulan Venattil27-Dec-05 20:00 

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.