|
so i guess no one knows the answer..oh well
|
|
|
|
|
SciGama wrote: var userCallback = e.UserState as Action<bool>
Your question is little bit confusing for me. whatever
If a class supports multiple asynchronous methods, or multiple invocations of a single method
then UserState property is used to determine which task raised the MethodNameCompleted event by checking the value of UserState property
|
|
|
|
|
Why can't I do the serialization successfully? I get an execption at the serialize line, yet I can do this using BinaryFormatter and SOAP Formatter. What am I missing?
public class person
{
public person() { ;}
public string firstname;
public string lastname;
public int Age;
}
public class persons
{
public persons() { }
public ArrayList personlist = new ArrayList();
}
<pre>[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
person p = new person();
p.firstname = "Tim";
p.lastname = "Duncan";
p.Age = 34;
persons ps = new persons();
ps.personlist.Add(p);
FileStream fs = File.Create("C:\\Temp\\test.xml");
XmlSerializer xs = new XmlSerializer(typeof(ArrayList));
xs.Serialize(fs,ps);
}
|
|
|
|
|
I think that
XmlSerializer xs = new XmlSerializer(typeof(ArrayList));
Should be
XmlSerializer xs = new XmlSerializer(typeof(persons));
and persons should have the Serializable attribute.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
your suggestion did not work. I still get an InvalidOperationexception at the serialize line! The exception says "unable to cast an object of type xmlSerialization.persons to type system.collections.Arraylist".
modified on Tuesday, December 14, 2010 8:24 PM
|
|
|
|
|
Software2007 wrote: unable to cast an object of type xmlSerialization.persons to type system.collections.Arraylist
Just use List<Person> for the collection of person in place of ArrayList .I think that will work.
|
|
|
|
|
your suggestion worked. The 2 samples below worked. Could you tell me why I can't use ArrayList though? Is there anything else I need to do to get Arraylist to work, or does it just not work?
Thanks
public List<person> personlist = new List<person>();
...
...
XmlSerializer xs = new XmlSerializer(typeof(persons));
xs.Serialize(fs,ps);
OR
public List<person> personlist = new List<person>();
.....
.....
XmlSerializer xs = new XmlSerializer(typeof(List<person>));
xs.Serialize(fs,ps.personlist);
|
|
|
|
|
Software2007 wrote: Could you tell me why I can't use ArrayList though?
You could use it, But I just was giving you a alternate way of accomplishing task.
See THIS[^], You might get idea on how to use ArrayList Serialization.
And for the serialization I think second one is appropriate.
|
|
|
|
|
When you get exceptions of a 'general' type like InvalidOperationException it is important to investigate the Inner Exception to determine the exact cause.
Just in case you do not know how to do this. When the Exception dialog pops up look below and to the left of the main 'Troubleshooting Tips' box and you will see a 'View Detail' link under 'Actions'. Click it. Expand the 'Inner Exception' node and you will see lots of useful stuff.
The important one in this case is the Message, which before making the changes I suggested said that "it was unable to convert persons to an ArrayList " and after making the changes said "person was unexpected and that use of XmlInclude attribute was recommended".
Following this up led me to Troubleshooting Common Problems....[^] on MSDN.
Have a read and see if it helps you to resolve your problem. If not, I have the solution so post a message and I'll explain it.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Ok,got it. Basically I needed the syntax like the following. I need to do some more reading I guess.
Type[] extraTypes = new Type[1];
extraTypes[0] = typeof(person);
XmlSerializer xs = new XmlSerializer(typeof(ArrayList), extraTypes);
Thanks
modified on Wednesday, December 15, 2010 9:34 AM
|
|
|
|
|
|
public class Program
{
[Serializable]
public class person
{
public person()
{
;
}
public string firstname;
public string lastname;
public int Age;
}
[
XmlInclude(typeof(person))
]
public class persons
{
public persons()
{
}
public ArrayList personlist = new ArrayList();
}
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
person p = new person();
p.firstname = "Tim";
p.lastname = "Duncan";
p.Age = 34;
persons ps = new persons();
ps.personlist.Add(p);
FileStream fs = File.Create("C:\\Temp\\test.xml");
XmlSerializer xs = new XmlSerializer(typeof(persons));
xs.Serialize(fs, ps);
}
}
The List<whatever> solution works because a generic List is strongly typed. It returns an instance of a 'whatever' when you index into it. ArrayList however, returns an instance of Object and the serialization code cannot, for whatever reason, resolve the object into a person.
Using XmlInclude , very rough potted explanation here , says "Hey I'm using instances of person in here somewhere, so if you find something you can't resolve, try person before bombing out."
Hope this helps.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Thanks. Your solution there was working for me. The problem was when I do
XmlSerializer xs = new XmlSerializer(typeof(ArrayList)); with or without the XMLInclude attribute, was not working!
the code shown here made it though.
Type[] extraTypes = new Type[1];
extraTypes[0] = typeof(person);
XmlSerializer xs = new XmlSerializer(typeof(ArrayList), extraTypes);
|
|
|
|
|
Software2007 wrote: The problem was when I do
XmlSerializer xs = new XmlSerializer(typeof(ArrayList));
with or without the XMLInclude attribute, was not working!
That's because you are not serializing an ArrayList directly. You are serializing an instance of persons which happens to contain an ArrayList.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
It makes sense! Sorry for the confusion.
|
|
|
|
|
Hello
I'm trying to figure out the best way to update TextBoxCell value on a Binded Datagridview
The values comes from a list of +/- 1000 allowed value
The Dgv is Binded to a datatable
I think that it will be too heavy and not necessary to create a ComBoBox column for that dgv
But I do not find many information about the use of a single Combobox cell to display "on the fly" when editing a TextBoxCell
Thank for any Help
N.B. : For now I'm using a ContextMenu with a ComBobox Item
|
|
|
|
|
Even if you find a suitable way of showing a ComboBox 'on the fly' I suspect that the time taken to load the +/- 1000 options will be at least as great (as heavy), if not greater than the time taken when using a DataGridViewComboBoxColumn .
From this point of view I cannot see why you do not use a ComboBox column. Or is there some other reason?
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Thank You Henry
To be honest I've very little experience about using ComboBox on a DataGridView
I know that it can be tricky and I don't really know when a ComboBoxCell is suitable instead of a ComboBoxColumn
But the constraints here are
- The DGV is Binded and normaly I use the AutoGenerate Column
- There is only ONE column editable in the DGV
- I want to see normal TextBox cell and make the Combo appears when a cell is edited
- There is only ONE List for the Combo
|
|
|
|
|
A ComboBoxColumn is made up of ComboBoxCells so to get a ComboBoxCell all you have to do is set that Column to be a ComboBoxColumn.
Here[^] is a sample using a ComboBoxColumn, work through it and see if it is anywhere near your requirements.
Pretty much anything that can be done in code can be done through the designer for DataGridViews. Look here[^] for an example.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
I have realized that I haven't answered your other points, I didn't really see them because I thought they were your sig.
olibara wrote: - The DGV is Binded and normaly I use the AutoGenerate Column
Using the 'Data Sources Window' you can set individual database columns to use specific types of DataGridViewColumns. By expanding the tree so that you can see the column of interest, make sure that your form is selected in the designer, go back to Data Sources and select the the column. It should display as a combobox which will list the types of controls that can be used, select the combobox option and away you go. When you drag the DataSource onto your form it will make a grid with a comboboxcolumn.
olibara wrote:
- There is only ONE column editable in the DGV
- I want to see normal TextBox cell and make the Combo appears when a cell is edited
The ComboBoxColumn looks like a TextBoxColumn until you edit/select it.
olibara wrote: - There is only ONE List for the Combo
That is normal.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Thank you Henri
I'm sorry to reply so late but I did'nt get the notification of your reply
I will investigate because using the Combobox directly in the DGV is far better than my actual solution to set the ComboBox in a contextMenu
It is not easy to find good explaination about the different way to use a combobox in a datagridview
|
|
|
|
|
Hi all,
I was wondering if there is a smooth way to accomplish the following:
Lets say I have a class that accepts delegates (or anonymous methods) that return strings.
Those refs are then stored.
I want to create an eventhandler that is fired when a result of such a delegate changes
(just like the TextChanged event of TextBox but maybe named: DelegateResultChanged)
I came up with a background thread that periodically calls the delegate and compares the result with the original result,
but that seems a little too much for archiving the desired result.
Any ideas on how this can be done "the right way"?
Any ideas are kindly appreciated
best regards
Andy
|
|
|
|
|
If you are using binding, you might want to consider looking at INotifyPropertyChanged as shown here[^].
The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it.
My latest tip/trick
Visit the Hindi forum here.
|
|
|
|
|
Unfortunately I am unable to use binding for this one.
I deal with Control objects that do not provide the PropertyChanged event.
Anyway, thanks a lot for your contribution!!
|
|
|
|
|
Well, the result changes when one or more of the inputs change, so what you really need to watch for is a change to the inputs. If this is on an object that implements change notification, you could pass that through and only check for a new result if the object reports a change.
But as for a changed event on the function itself... To my knowledge, no such thing exists. That function isn't going to re-run every time the inputs change, so the program doesn't even know what the new result is until you ask for it.
Off the top of my head, another alternative...
Instead of passing a function, wrap that up in a lightweight class:
public class FunctionWatcher
{
public FunctionWatcher(INotifyPropertyChanged caller, Delegate function)
{
}
private Delegate Callback;
public object Result { get; private set; }
public event EventHandler ResultChanged;
private void CallerPropertyChanged(...)
{
}
}
Again, this relies on having some object providing change notification... Otherwise your current solution might be the only one.
|
|
|
|