|
bhausahebshedbale wrote: I have one string in "HH:MM" format.
Want to store same in DateTime format but same in HH:MM format
No. Don't do that.
A timestamp is a value that ALWAYS has a timezone either implicitly or explicitly.
If you have only a time then it is not a timestamp. Just that simple. Thus attempting to coerce it into a timestamp is at best difficult and worse will end up causing more problems than you think it will fix.
Create your own class and create the XML supporting classes/methods to support it as such.
|
|
|
|
|
Hello!
I have a PropertyGrid in an application displaying some properties in a class. One property has it's own TypeConverter to display an array of strings.
Issue
I would like to change the TypeConverter of the property in runtime.
Example
I have included a simple example code. You should be able to just paste the code in a Windows Forms Application, compile and run. Remember to create a PropertyGrid (propertyGrid1) and a button (button1) in the Form and add the button's click event.
Notice the two static string arrays in the Form1 class. These arrays are used with the TypeConverters NameList and SentenceList.
When the application start you will see the PropertyGrid displaying the name list in the property called Item. When you click the button I want the list of names to change to the list of sentences instead. I imagined the SwopList() method in the Props class should handle this. I call the SwopList() method with the button's click event.
In the SwopList() method I fetch the PropertyDescriptor object of the Item property. Then I can see what TypeConvert is used with the property PropertyDescriptor.Converter. From that point I just want to swop the TypeConverter (like the code I have commented out). But this don't work as PropertyDescriptor.Converter is read only
Any solution?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public static string[] Names = new string[] {"Jon Smith", "Fred Perry", "Foo Bar" };
public static string[] Sentences = new string[] { "Hi hello!", "Bye", "Peace and long life", "Live long and prosper" };
Props properties = new Props();
public Form1()
{
InitializeComponent();
propertyGrid1.SelectedObject = properties;
}
private void button1_Click(object sender, EventArgs e)
{
properties.SwopList();
propertyGrid1.Refresh();
}
}
public class Props
{
string name = Form1.Names[0];
string sentence = Form1.Sentences[0];
string item;
public Props()
{
item = name;
}
public void SwopList()
{
PropertyDescriptorCollection pdc = System.ComponentModel.TypeDescriptor.GetProperties(this);
PropertyDescriptor pd = pdc["Item"];
if (pd.Converter is NameList)
{
item = sentence;
}
else if (pd.Converter is SentenceList)
{
item = name;
}
}
[TypeConverter(typeof(NameList))]
public string Item
{
get { return item; }
set { item = value; }
}
}
public class NameList : TypeConverter
{
public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
{
return true;
}
public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
{
return new StandardValuesCollection(Form1.Names);
}
}
public class SentenceList : TypeConverter
{
public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
{
return true;
}
public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
{
return new StandardValuesCollection(Form1.Sentences);
}
}
}
Best regards,
/Steffe
|
|
|
|
|
Theoretically, you cannot change the value of the attribute during runtime; it is compiled. Hence, recompile and it would work. That would require unloading of the type, which is a little bit overkill.
Alternatively, you create a TypeConverter that works as a proxy, using either the implementation of NameList or SentenceList as the actual implementation.
Alternatively, you create two exact the same classes (different names though), decorate each with its own converter, and create a converter to kick the data from object1(class1) to object2(class2).
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Thanks!
I solved it by using your "proxy" suggestion
|
|
|
|
|
Cool
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Anyone knows good tool or open source tool for image based automation like i want to find any inout image on windows or web application and i need to do some automation on that image if it is able to find that image. I have an java applet form which i need to automate through c# tool i am not able to access its controls so i am going for image based automation which is required also. I looked at sikuli , aspire , auto-it and others but no where mentioned how it will be integrated in c# project.
Please help i just want like below :- i got one link but that too doesn't worked
http://www.youtube.com/watch?v=rF2G87b6qiQ
|
|
|
|
|
|
Thanks ...Any other option through which i can image based automation other than auto-it and sikuli
|
|
|
|
|
Renorex doing it but i want to find some open source . See i want like this :-
[^]
|
|
|
|
|
I'm not going to Google.
If you have a specific question, please ask.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Yeah..Will autoit be helpful for me for my requirement..
|
|
|
|
|
Hello Everyone,
I have completed MCTS , microsoft certification,
I would like to know,which certification will be best as i am working on C#, SQL SERVER, MVC.
Please advice
m
|
|
|
|
|
Mukesh Ghosh wrote: I would like to know,which certification will be best Best for what? A certification is only a piece of paper, and while it may assist in seeking a job, most employers are more interested in experience and a practical demonstration of your knowledge and skills.
|
|
|
|
|
I know. But as per our company policy i have to be microsoft certified.
Now , i have completed MCTS & that is quite old, but now i am bit confuse any certification that might help me in future as i am a c# developer.
m
|
|
|
|
|
Mukesh Ghosh wrote: But as per our company policy i have to be microsoft certified. Then talk to the people responsible for the policy and ask them what certification you need.
|
|
|
|
|
hey guys is there an example on how to get username and password in a file?
input username and pass look it up if ok write ok..
|
|
|
|
|
Most of us use a database for data storage, this article [^]reads and writes to a file and may help you. Getting the logon details are left to the student!
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
|
thx guys.i just need it really simple..
the part that im stuck on is the lookup of the user and pass..im of for one but when it comes to to strings i get confused..
|
|
|
|
|
techker2 wrote: when it comes to to strings i get confused. In what way? You can read a file line by line and use a simple string compare (http://msdn.microsoft.com/en-us/library/858x0yyx(v=vs.110).aspx[^]), to find the keyword you are interested in. Alternatively, you could create a serializable class and let the objects do the work.
|
|
|
|
|
from the readLine
someting like
string Lookup = Console.Readline(username and password)
|
|
|
|
|
|
Just started school not to long ago..i just wanted to practice some stuff before a project..
Thx!
|
|
|
|
|
Then that book I suggested is an excellent introduction to C# and would help you a lot in any small project. It is very well written with lots of sample code, and easy to read, even if English is not your first language.
|
|
|
|
|