|
You can't - nothing that is specific to an ASPX is going to interact with Excel. You can write C# code that generates an Excel file, and then save it and push it down to the browser, if that's what you want to do.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Hello again
I have two forms, one being opened by another.
What I want to do is that the second form that is opened by the first one is when it is closing, I want it to run a method in first form.
The code I used is something like this.
private void frmAddCategory_FormClosed(object sender, FormClosedEventArgs e)<br />
{<br />
frmCore core = new frmCore();<br />
core.comboRefresh("newPost");<br />
<br />
<br />
}
It doesnt work. I checked with debug and it seems to run, but nothing seems to happens to the first form.
Its a dropdownlist that has items in it, the second form adds new items to it in a database.
the method that is called is taking data from a database and updates the dropdownlist with the new items.
|
|
|
|
|
ah those vb programmers
frmCore core = new frmCore(); creates a new instance of your mainform. so calling a method on this new instance will not affect the first form.
i wouldn't do it like this anyway.
my preferred solution for such things is this:
public class frmAddCategory:Form
{
public string NewPost
{
get
{
return txtNewPost.Text;
}
}
}
public class frmCore:Form
{
private void SomeButton_Click(object sender, EventArgs e)
{
frmAddCategory blah = new frmAddCategory();
if (blah.ShowDialog() == DialogResult.OK)
{
myComboBox.Items.Add(blah.NewPost);
}
}
}
greets
M@u
|
|
|
|
|
m@u wrote:
public class frmAddCategory:Form
{
public string NewPost
{
get
{
return txtNewPost.Text;
}
}
}
public class frmCore:Form
{
private void SomeButton_Click(object sender, EventArgs e)
{
frmAddCategory blah = new frmAddCategory();
if (blah.ShowDialog() == DialogResult.OK)
{
myComboBox.Items.Add(blah.NewPost);
}
}
}
What is this ? This looks totally out of topic to me !
|
|
|
|
|
Im not a VB coder, but I guess I use their method or something like that
Anyway. It looks like it pass a value to a variable to the first form, which isnt what I wanted to do. I wanted to call a method. But maybe a similiar way to do like you stated above.
Can you show me some sample code to call a method (function, procedure, whatever :P)
|
|
|
|
|
sorry i thought you want to pass a value entered in frmAddCategory.
for calling a method, like navaneeth says, a delegate/event would be appropriate:
public class frmAddCategory
{
public event EventHandler CategoryAdded;
protected virtual void onCategoryAdded(EventHandler e)
{
if (CategoryAdded != null)
{
CategoryAdded(this,e);
}
}
private void someEventHandler(...)
{
onCategoryAdded(EventArgs.Empty);
}
}
in the calling Form after creating frmAddCategory say
myForm.CategoryAdded += new EventHandler(myForm_CategoryAdded);
and in the myForm_CategoryAdded you can then add the Entry to the Combobox.
|
|
|
|
|
Deques wrote: frmCore core = new frmCore();
This will create a new instance for the form and method in that instance will be called.
I prefer to use delegates in this scenario. Create delegate in second form and hook a method handler from first form when second form is invoked. On second forms FormClosed event, invoke this delegate.
Hope it helps
|
|
|
|
|
How does it work? I am not familiar with delegates >.<
Could you provide me some code examples, please?
|
|
|
|
|
|
Deques wrote: I am not familiar with delegates
Delegates are function pointers in which you can assign a function's reference, and when delegate is invoked, supplied function will be called.
For explaining this we have two forms say Form1 and Form2 . I am invoking Form2 from Form1's load event. Inside Form2 I have declared a delegate. See the Form2 code below
public class Form2 : System.Windows.Forms.Form
{
public delegate void FormClosed();
public FormClosed FormClosedHandler;
private void Form2_Closed(object sender, System.EventArgs e)
{
FormClosedHandler();
}
} In the above code, you can see I have created a FormClosed() delegate and an object for that delegate. This object I will be assigning from the Form1 just before Form2 is shown. See the Form1 code below
public class Form1 : System.Windows.Forms.Form
{
private void Form1_Load(object sender, System.EventArgs e)
{
Form2 obj = new Form2();
obj.FormClosedHandler += new Form2.FormClosed(this.Form2ClosedHandler);
obj.Show();
}
} In this I have assigned a private method Form2ClosedHandler to the delegate. So when delegate is invoked, this private method in Form1 will get called. You can refresh your combo inside this method.
Delegates are good for communicating between classes.
Hope this helps
|
|
|
|
|
Thanks for the information
I have tried this code, but when I build it I get this error the private method I have assigned with. I thnk I have done something wrong
It says "Method name expected"
This is the code I used for form 1
private void btnNewPost_Click(object sender, EventArgs e)
{
Forms.frmAddCategory addcats = new frmAddCategory();
addcats.Refresher += new Forms.frmAddCategory.refreshcat(this.comboRefresh("newPost"));
addcats.ShowDialog();
}
comboRefresh(string blah)
{
}
and this is for the form 2
public partial class frmAddCategory : Form
{
public delegate void refreshcat();
public refreshcat Refresher;
private void frmAddCategory_FormClosed(object sender, FormClosedEventArgs e)
{
Refresher();
}
|
|
|
|
|
Deques wrote: addcats.Refresher += new Forms.frmAddCategory.refreshcat(this.comboRefresh("newPost"));
addcats.Refresher += new Forms.frmAddCategory.refreshcat(this.comboRefresh);
If your comboRefresh() method takes string parameter, you should change the delegate like
Deques wrote: public delegate void refreshcat();
public delegate void refreshcat(string str);
Deques wrote: private void frmAddCategory_FormClosed(object sender, FormClosedEventArgs e)
{
Refresher();
}
private void frmAddCategory_FormClosed(object sender, FormClosedEventArgs e)
{
Refresher("string to be passed");
}
|
|
|
|
|
Thanks. It works now
Only thing that the combobox doesnt update directly sometimes. But thats another problem
|
|
|
|
|
Welcome. Glad to hear that it helped
|
|
|
|
|
implement delegate and raise event.
the problem in your code it's making the new copy of your form and you need to perform some action on your previously opened form
|
|
|
|
|
Hi all, I am newbie to C#
I would like to implement a function where the variable passed
should not be changed during execution. In C++ I used void foo( const int a ).
What I can do in C# in order to ensure that my variable is not touched
If i use void foo(const obj MyObj) I have an error. Is the only way to pass
an already const member?
Kind Regards
ManuStone
|
|
|
|
|
Hi
Most Parameters are passed as values to a function so if you call
void foo(int param)
{
param = 2;
}
void main()
{
int i = 1;
foo(i);
Console.WriteLine(i);
}
the output will still be 1.
the only problem you could have would be, if you pass an object and inside your method, a property of that object is changed. this will affect the original object if it's a reference-type (class) for a struct no changes are applied to the original.
greets
m@u
|
|
|
|
|
m@u wrote: Most Parameters are passed as values to a function
No, just value types.
m@u wrote: the only problem you could have would be, if you pass an object and inside your method, a property of that object is changed
You mean mutable reference types rather than objects, ints and doubles are objects too. You do clarify that in the next sentence but it could be read wrongly.
|
|
|
|
|
as far i know, the passed parameters will not change unless they indicated as ref or out
just use your method
foo(myObj);
I Wish the Life Had CTRL-Z
|
|
|
|
|
subai wrote: as far i know, the passed parameters will not change unless they indicated as ref or out
Incorrect. The passed parameters will not change if they are immutable (e.g. a string) or if they are value types (e.g. int, double, DataTime)
If the types are reference types that are mutable (and the vast majority are) then there is every possibility that the object passed as a parameter can itself change. But you cannot change it to another object.
|
|
|
|
|
thank you very much for telling me my wrong thought
I Wish the Life Had CTRL-Z
|
|
|
|
|
Dear All,
Warm Greetings!!!
I want to List all the domains in my network.
How can I perform this?
Can anyone help me to get this done?
Thanks a lot in advance.
Best Regards,
M. J. Jaya Chitra
|
|
|
|
|
Where can i get open source code for Media RSS 2.0 parser?
I want the output to be generated in XML format by passing url of type Media RSS 2.0.
For this where can i get open source code?
Rajshri
|
|
|
|
|
|
Hai iam working with list and i have added items to list and how can i find whether the items r added to list or not using windows applications using c# and how can i display the items in list in windows applications plz any one help me in this problem
|
|
|
|