|
Try to separate code for design and code fore runtime.
You can use constuction:
if (this.DesignMode)
{
// Design actions
}
else
{
// Runtime actions
}
You can save info to logfile.
Also you can see callstack, when you see error - analize this info.
Best regards, Alexey.
|
|
|
|
|
How can I write in the fields of a form outside of its class? For example, I have a Form1 and a DoWork class. I want the DoWork class write something in a text field in Form1. I can't access the fields directly, so there should be another way.
|
|
|
|
|
This question is asked so many times in the forum....you really ought to search the forum before asking.
Basically, create a property in your form that exposes the variable:
string myVar;
...
public string MyVar
{
get
{
return myVar;
}
}
And your DoWork class just needs an instance of Form1 to access its public members:
class DoWork
{
private Form1 form;
public DoWork(Form1 formInstance)
{
this.form = formInstance;
string theVar = this.form.MyVar;
}
}
|
|
|
|
|
adol_w wrote: I can't access the fields directly, so there should be another way.
What exactly do you mean with that?
Some first guesses:
Change their visibility to public or better declare a public property with get- and/or set-body (as needed) to access them.
Hand over an instance of your Form1 class when you construct the DoWork class instance, store it in a private field and use it to access the fields when needed.
www.troschuetz.de
|
|
|
|
|
The quick and proper way:
Create public properties for the fields in DoWork and access them that way.
The slow and sneaky way: Use Reflection, like this:
FieldInfo fi = myDoWork.GetType().GetField("someFieldInDoWork", BindingFlags.NonPublic | BindingFlags.Instance);<br />
fi.SetValue(myDoWork, someValue);
Regards,
Alvaro
The bible was written when people were even more stupid than they are today. Can you imagine that? - David Cross
|
|
|
|
|
This has been asked so many times I wrote an article about it: See Passing values to forms[^]
"On two occasions, I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able to rightly apprehend the kind of confusion of ideas that could provoke such a question."
--Charles Babbage (1791-1871)
My: Website | Blog
|
|
|
|
|
Sorry, I can't believe I didn't see that article. Thanks for the answers. I just hope nothing significant has changed in .net 2.0.
|
|
|
|
|
Hi
I am doing a division and the result gives me an answer with decimal places. How do I remove all the characters after the decimal place?
|
|
|
|
|
double d = 13/7;
int i = Convert.ToInt32(d);
|
|
|
|
|
|
That depends.
Do you want to truncate or round the value?
Are you going to process the value further, or is it only to be displayed?
If you want to truncate the value (remove decimal part), cast the value to int or use Math.Truncate.
If you want to round the value (to nearest integer), use Math.Round.
If you want to round it only for displaying it, do the rounding when you convert it to a string, using ToString("n0").
---
b { font-weight: normal; }
|
|
|
|
|
hi
How to invoke post back.I need some function like invalidRect in win app.
thank you for help
best regards
|
|
|
|
|
Form.Invalidate(Rectangle)
|
|
|
|
|
Hi All,
A Text Box on a Form of mine is bound to a Numeric SQL Server field. Is there any easy way to Format the contents to : '9.00', and Not '9.0000' as it is at the moment?
[I Bind in code so was thinking I could include formatting there]
Thanks
Jonny
|
|
|
|
|
Take a look at this MSDN topic covering Numeric Format Strings[^].
There may also be a way doing the formatting during data binding. I remember doing something like that on my website. But to help you specifically with that some code would be helpful.
www.troschuetz.de
|
|
|
|
|
Thanks Stefan,
Heres the code :
this.textBoxAmount.DataBindings.Add("Text", myBindingSource, "Amount")
There is another .Add Constructor, which includes 'formatString', so perhaps I can use that?
Thanks
Jonny
|
|
|
|
|
|
How can I run a Select query from a datatable so that it only brings the
fields I want?
ALBSHAH
|
|
|
|
|
SELECT list_of_fields_you_want_seperated_with_comma FROM ...
--------------------------------------------------------
My development blog
Q:What does the derived class in C# tell to it's parent?
A:All your base are belong to us!
|
|
|
|
|
Hi there
Why do you need this functionality?
If there isn't too much data in the table, you could copy the table and then remove the columns you didn't need, and then Select from it:
DataTable newTable = oldTable.Copy();
newTable.Columns.RemoveAt(1);
newTable.Columns.RemoveAt(3);
dgDisplay.DataSource = newTable.Select("WHERE age < 50");
Kind regards - Jakob
*********************************************
Three kinds of people in the world:
- Those who can count..
- Those who can't!
10 kinds of people in the world:
- Those who understand binary
- Those who don't
|
|
|
|
|
I am using Infragestics Ultra webGrid and one of the column in that gird is Hyperlink.
I want to pass multiple values in Navigate URl
How do i do that???
Thanks
|
|
|
|
|
As you have paid for it it should be best to ask Infragestics...
|
|
|
|
|
Hi,
How can i create a pop up menu like the one of Mail button on IE?Please help me.
Thanks,
LMHP
|
|
|
|
|
Hi,
i want to create a pop-up menu like the Mail button for the IE. How can i do this?
Thanks in advances.
LMHP
|
|
|
|
|
comboBox1.DataSource = AnyDataset;
comboBox1.DisplayMember = "Name"
comboBox1.ValueMember = "Id"
while writting this code.the selectedIndexchnaged event of the combo fire.
i don't want the same.I want to event to fire when the item is selected from the interface.
Rohin
|
|
|
|