|
The value N6BYK6 is missing the first single quote. Risk of SQL injection attacks aside, it may make things a bit more readable to write a small function to quote text values. That way, instead of relying on the visually confusing "','", you could just say SingleQuote(firstName). Make sense?
V
|
|
|
|
|
Is it possible the items in ListView control to be set as multiline, so the text to be displayed in two lines for one item?
thanks.
|
|
|
|
|
If \r\n doesnt work, then you'll have to inherit the control and handle the paint events.
|
|
|
|
|
The managed ListView control doesn't support multiline rendering. You'll have to subclass it and render the ListView yourself.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
I have 2 forms, form1 and form2. form1 has a function called components. I need now, for form2 to execute this function on form1 as per normal. I have no clue on form linking, please help me! Thanks!
|
|
|
|
|
You need to pass somehow form1 to form2.
Create a property of type From1 in Form2. Then, after creating as Form2 assign Form1 to form2.Form1. (I hope this sentence is understandable )
public class Form2 : System.Windows.Forms
{
private From1 m_Form1 = null;
public Form1 Form1
{
get {return this.m_Form1;}
set {this.m_Form1 = value;}
}
public void SomeFunctionUsingComponentsOnForm1()
{
if (this.m_Form1 == null)
throw new ArgumentException("Form1 is not assigned.");
this.m_Form1.components();
}
}
public class Form1 : System.Windows.Forms
{
public void ShowForm2()
{
Form2 form2 = new Form2();
form2.Form1 = this;
form2.Show();
}
}
/cadi
24 hours is not enough
|
|
|
|
|
Thanks Cadi for the swift reply! Yes I understand what you were saying on the top but your program doesn't really go with my understanding, especially the bottom part, because it looks like its reopening form2? But both forms are open already and I need for form2 to get form1 to run its function called components. Maybe you could explain your program abit more? Thanks!
|
|
|
|
|
Ok... so form1 is not the owner of form2 (ok, if it would be like this the Owner property would have been ok...)
Hmm... this leeds me to a second aproach.
If both forms have the same owner then you could search for form1 using something like this: this.FindForm().OwnedForms
If there is always only ONE instance of form1 you could try somthing like this:
public class Form1 : System.Windows.Form
{
private static Form1 m_GlobalInstance;
public Form1()
{
m_GlobalInstance = this;
}
protected override void OnClosed(EventArgs e)
{
m_GlobalInstance = null;
base.OnClosed (e);
}
public static Form1 GlobalInstance
{
return m_GlobalInstance;
}
}
public class Form2 : System.Windows.Form
{
public void SomeFunctionUsingComponentsOnForm1()
{
if (Form1.GlobalInstance == null)
throw new ArgumentException("Form1 is not yet created.");
Form1.GlobalInstance.components();
}
}
/cadi
24 hours is not enough
|
|
|
|
|
There is no special mechanism for Form linking. All you have to do is somehow pass a reference to form1. If you are creating form2 from within form1, you can do something like
class Form2 : Form
{
Form1 form1;
public Form2(Form1 form1)
{
this.form1 = form1;
}
}
and then call form1.SomeMethod . Otherwise, you can expose a property in Form2 and set it to form1.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
Hey thanks man for replying so fast, but I'm not quite sure if we're on the same page haha... Okay you see, both forms are open and no, form1 doesn't create form2, just opens it with simply a
form2 form = new form2();
form.Show();
I need to use this function called "components". On form1 I would just simply call this function with simply
components();
but because I need now for form2 to execute this function ON FORM1 as per normal, it won't let me cause components doesn't exist on form2.
Okay yes I'm very blur so here's sort of a 'template' to help me understand better.
private void pictureBox1_Click(object sender, System.EventArgs e)
{
//please enter code here if its meant to be here thanks!
}
|
|
|
|
|
Obviously, this function belongs in a third class, where both forms can access it. Or, if it's intrinsic to a form, it should be in a base class that derives from Form and which both Forms inherit from.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
You need to get a reference to Form1.
+ if Form2 has an instance of Form1, for example f1, then call f1.components()
+ else you iterate through all open form, and find a form whose name is Form1'name, and then cast this form to Form1 and call the method. example
Form f1 = "Open form whose name is Form1's name";
((Form1)f1).components();
|
|
|
|
|
Uhhh...no, you need to do it the right way and seperate the function into a library. There is no reason for one form to know anything about another one, unless it's a child form.
If the function is in a library, then each form can pass itself as a reference to a library method MUCH easier than trying to get one form to get a reference to another. It just makes for much cleaner code.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Do you think he was trying to correct my answer, or that he was trying to give an answer to the guy who asked in the first place ? I get a lot of answers appended to mine, all of a sudden...
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
I think he was trying to answer the OP.
Damn! How hard is it to click Reply on that post and not someone else's answer!
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
I suspect a lot of people read all replies, then hit reply on the last on they were reading, not being used to threading in a forum perhaps ?
I'm thinking about a series of articles on good design, seeing as a lot of these questions get answers that ignore design as an issue ( and I've really enjoyed helping a few people with complex design questions of late ). Have you seen any articles like this on CP ? I'll do my own search, obviously.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
It's pretty sparse on the articles on CP. I've seen lots more on MSDN. Hey! A good place to start for source material would probably be Microsoft's Patterns and Practices[^] site. LOT'S of good stuff in there.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Dave Kreskowiak wrote:
Patterns and Practices[^]
Wow - there is a site ? I own about 8 of the books in that series, I didn't realise there were online resources as well.
The last two I bought were on security and ASP.NET performance and scalability. Close to 1000 pages each, so I have some reading to do.....
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Hey Dave, I'm not sure if I understood your solution? Separate my function into a library? Well you see its a function that just adds components to Form1, and it is written on Form1's class and works perfectly fine with a click of anything
But yes I posted this question cause now I ALSO need Form2 to be able to call this same function for it to work as per normal on Form1. They both belong to the same namespace webtest and I use Visual Studio 2003... Please help man, thanks!
|
|
|
|
|
If this is the case, it's a bad idea to move it to a library. I thought your method was more generic than that, doing something on more than one form. If it only deals with one form, it's better to leave the method on that form and make it public so other classes can call it.
Follow the code samples in the other posts. They'll show you how to add a reference for Form1 on Form2. From there, it's a piece of cake.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
What I don't get is, if it's a web app, why does Form2 need to call a method that pertains to form1 ? I think something else is not right here.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
It's a web app? I didn't see that anywhere.
I'll go back and look... when I get a chance.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Dave Kreskowiak wrote:
It's a web app?
No, it's not, but the project is called 'webapplication', because it uses the google API. It sounds like he has no need to pass anything anywhere, I'm not sure where he's been confused.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Hey man thanks for the suggestion, you make quite alot of sense and I think its exactly what I need to do but unfortunately it still doesn't work. The function is just simply not called. So I took your advice and I did
private void button1_Click(object sender, System.EventArgs e)
{
Form1 form = new Form1();
form.components();
this.Close();
}
in Form2 and only my Form2 closed without Form1 doing what it was suppose to do. It basically adds a shitload of components to itself with this.Controls.Add and yeah it didn't work. Or if you think its quite crap, still not even this works
private void button1_Click(object sender, System.EventArgs e)
{
Form1 form = new Form1();
form.Close();
this.Close();
}
even though both times were ABLE TO BE COMPILED. so maybe you might have a suggestion as to why? May I'm not doing my classes or namespace or the USING commands properly. Both forms belong to a namespace called webtest and the classes Form1 and Form2 are on different pages using Visual Studio 2003. Please help man, I'd very much appreciate it, thanks!
|
|
|
|
|
DJdC wrote:
Form1 form = new Form1();
form.components();
This is really terrible. I assume the components function adds controls to Form1 ? It will add them to the instance of the form which you call close on ( and which is never shown ).
DJdC wrote:
even though both times were ABLE TO BE COMPILED.
That just means that you have no syntax errors, don't get too excited if your code compiles, that guarentees very little beyond a basic syntax check.
I think you need to do some more explaining
1. Is this a web application ?
2. Why do you need to call this method within Form2 ?
3. What are you trying to achieve through using this method ?
4. What do you expect to happen because you called this method from Form2 ? What is going wrong that in your mind is caused by the method not being called ?
Christian Graus - Microsoft MVP - C++
|
|
|
|