|
these articles cannot be accessable.
|
|
|
|
|
I'm using a PropertyGrid control, and I want to display only some particular properties. I know I have to implement ICustomTypeDescriptor in my class so the grid can use GetProperties method. And that's the problem - I need only that method, but the interface is quite big, contains many methods. I know I always can write empty method implementation but to me it just doesn't seem the right thing to do. Is there another way? If not, could anyone post some piece of code which implements the GetProperties method?
|
|
|
|
|
Is there another way?
Not that I'm aware of
If not, could anyone post some piece of code which implements the GetProperties method?
public class MyDescriptor : ICustomTypeDescriptor<br />
{<br />
public TypeConverter GetConverter()<br />
{<br />
return TypeDescriptor.GetConverter(this, true);<br />
}<br />
<br />
public EventDescriptorCollection GetEvents(Attribute[] attributes)<br />
{<br />
return TypeDescriptor.GetEvents(this, attributes, true);<br />
}<br />
<br />
EventDescriptorCollection System.ComponentModel.ICustomTypeDescriptor.GetEvents()<br />
{<br />
return TypeDescriptor.GetEvents(this, true);<br />
}<br />
<br />
public string GetComponentName()<br />
{<br />
return TypeDescriptor.GetComponentName(this, true);<br />
}<br />
<br />
public object GetPropertyOwner(PropertyDescriptor pd)<br />
{<br />
return this;<br />
}<br />
<br />
public AttributeCollection GetAttributes()<br />
{<br />
return TypeDescriptor.GetAttributes(this, true);<br />
}<br />
<br />
public PropertyDescriptorCollection GetProperties(Attribute[] attributes)<br />
{<br />
PropertyDescriptorCollection pdc = TypeDescriptor.GetProperties(this, attributes, true);<br />
<br />
PropertyDescriptor[] pd = new PropertyDescriptor[x];<br />
<br />
for (int i=0; i<pdc.Count; i++)<br />
{<br />
if (pdc[i].Name.Equals("Property1"))<br />
{<br />
pd[0] = pdc[i];<br />
}<br />
else if (pdc[i].Name.Equals("Property2"))<br />
{<br />
pd[1] = pdc[i];<br />
}<br />
...<br />
}<br />
<br />
return new PropertyDescriptorCollection(pd);<br />
}<br />
<br />
PropertyDescriptorCollection System.ComponentModel.ICustomTypeDescriptor.GetProperties()<br />
{<br />
return ((ICustomTypeDescriptor) this).GetProperties(new Attribute[0]);<br />
}<br />
<br />
public object GetEditor(Type editorBaseType)<br />
{<br />
return TypeDescriptor.GetEditor(this, editorBaseType, true);<br />
}<br />
<br />
public PropertyDescriptor GetDefaultProperty()<br />
{<br />
return TypeDescriptor.GetDefaultProperty(this, true);<br />
}<br />
<br />
public EventDescriptor GetDefaultEvent()<br />
{<br />
return TypeDescriptor.GetDefaultEvent(this, true);<br />
}<br />
<br />
public string GetClassName()<br />
{<br />
return TypeDescriptor.GetClassName(this, true);<br />
}<br />
}<br />
|
|
|
|
|
Thanks a lot! One more question - the class that implements the ICustomTypeDescriptor is the class I will be forwarding to tge PropertyGrid right? Sorry if this is a supid question...
|
|
|
|
|
the class that implements the ICustomTypeDescriptor is the class I will be forwarding to tge PropertyGrid right?
Yes
"I think I speak on behalf of everyone here when I say huh?" - Buffy
|
|
|
|
|
hi ,
i am trying to fetch the datafrom database into dataet and display it in a richtextbox in rtf format.
it displays a illegal file format.
please throw some light on where i am mistaken
below is the code for your reference
{
string st;
string st1 = "";
st = "select * from TPNeeds";
SqlDataAdapter ad = new SqlDataAdapter(st,con);
ad.Fill(dataset11,0,0,"TPNeeds");
DataTable dt = dataset11.Tables[0];
ArrayList arr = new ArrayList();
//Encoder e1 = Encoding.UTF8.GetEncoder();
Encoding encode = Encoding.Default;
foreach(DataRow row in dt.Rows)
{
st1 += row["NeedText"].ToString();
//richTextBox2.Rtf = encoding.GetString(binaryData,0,binaryData.Length);
}
byte[] rawBytes = Encoding.ASCII.GetBytes( st1 );
using ( MemoryStream ms = new MemoryStream(rawBytes) )
{
richTextBox2.LoadFile( ms, RichTextBoxStreamType.RichText );
}
// System.IO.MemoryStream stream = new System.IO.MemoryStream(StrToByteArray(st1));
// richTextBox2.LoadFile(stream,RichTextBoxStreamType.PlainText);
//richTextBox2.LoadFile(stream,RichTextBoxStreamType.RichText);
//richTextBox2.Rtf = encoding.GetString(bytearr,0,bytearr.Length);
}
catch(Exception ex)
{
MessageBox.Show(ex.Message.ToString());
MessageBox.Show(ex.StackTrace.ToString());
}
}
public static byte[] StrToByteArray(string str)
{
System.Text.ASCIIEncoding encoding=new System.Text.ASCIIEncoding();
return encoding.GetBytes(str);
}
mrlathiwala
|
|
|
|
|
Is the data in the database a string in rich text format? Or is it a string in plain text format?
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Horrific Minnesota Radio
Judah Himango
|
|
|
|
|
it's in plain text format
|
|
|
|
|
Then why are you trying to load it as RichText? Plain text should be set in the RTB as RTB.Text = plainText.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Horrific Minnesota Radio
Judah Himango
|
|
|
|
|
how to play a movie file stored on hard disk
|
|
|
|
|
|
Download managed DirectX 9 SDK.
Add a reference in your project to Microsoft.DirectX.AudioVideoPlayback.
Video.Play("someFile.mpg");
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Horrific Minnesota Radio
Judah Himango
|
|
|
|
|
I am making a CustomLabel class which extends Label and abstract class CustomBehaviour. For some reasons the class is not an interface. How do you do this in C#? I can extend only one class at a time
|
|
|
|
|
For some reasons the class is not an interface. How do you do this in C#?
What do you mean ?
|
|
|
|
|
I mean that I have two classes to inherit from, and I don't know hot to best do it. If the CustomBehaviour was an interface there would be no problem, bu it is an abstract class. I can't inherit from two classes, can I? And I wonder how to implement this.
|
|
|
|
|
Why can't you just have your custom behavior code inherit from the label class and then make all your new classes inherit from your custom behavior class? Thats how I do it!
Maybe I'm not understanding the problem though
|
|
|
|
|
|
This is a class I wrote for my program's needs. It adds some methods and fields to Label. However, the case is how to make a class like MyLabel which inherits from Label and my class?
|
|
|
|
|
|
I came up with this:
abstract class AbstractCustomLabel : Label {}
abstract class AbstractBehavioralCustomLabel : CustomBehaviour {}
public class CustomLabel : AbstractBehavioralCustomLabel
{
public CustomLabel code
public override void OnDraw code
}
Is it acceptable?
|
|
|
|
|
How do word covert pdf
How do word covert pdf
|
|
|
|
|
hmm are you interested in writing converter Word (RTF) to PDF files? Or you just want tool to do that?
In latter case type "word to pdf" into google. Btw I use PDF Creator[^]. For documentation of school projects it's fine.
David
Never forget: "Stay kul and happy" (I.A.)
David's thoughts / dnhsoftware.org / MyHTMLTidy
|
|
|
|
|
Hi,
I have a numer in a string that may or may not have a decimal delimiter and some numbers afterwards, e.g. 1234 or 1234,5 or 1234,567. Now I want to show this number to the user with thousand separators, and keep the decimal precision from the original number. I.e. the number should be 1.234 and 1.234,5 and 1.234,567
If I use the following code
NumberFormatInfo nfi = new NumberFormatInfo();<br />
nfi.NumberDecimalSeparator = ",";<br />
nfi.NumberGroupSeparator = ".";<br />
double.Parse(m_value).ToString("N",nfi);
I'll get 1.234,00 and 1.234,50 and 1.234,57 - which is not what I want. Is there any other way to just add the thousand seperators and leave the decimal things unchanged ? It seems that nfi.NumberDecimalDigits misses a "dont mess with it" number...
Any ideas ?
/Jan
Do you know why it's important to make fast decisions? Because you give yourself more time to correct your mistakes, when you find out that you made the wrong one. Chris Meech on deciding whether to go to his daughters graduation or a Neil Young concert
|
|
|
|
|
If I understand you question, then I think you've got your nfi.NumberDecimalSeperator and your ndi.NumberGroupSeperator contents backwards. Try switching the two assignments around and see if that helps.
|
|
|
|
|
You could use something like that ...
string m_value = "12347890123456789,57";
string strhi = m_value;
string strlow = "";
int DecLocation = m_value.IndexOf(",");
int StrLen = m_value.Length;
if ( DecLocation >=0 )
{
strhi = m_value.Remove(DecLocation,StrLen-DecLocation);
strlow = m_value.Substring(DecLocation+1,StrLen-DecLocation-1);
m_value = Separ(strhi)+","+strlow;
}
else
m_value = Separ(m_value);
private string Separ(string str)
{
int i = str.Length/3;
int maxlen = str.Length;
if ( i*3 == maxlen)
i--;
string newstr = str;
for(int j=1;j<=i;j++)
newstr=newstr.Insert(maxlen-j*3,".");
return newstr;
}
|
|
|
|