|
It's all forgivable if you're new .
The really important one in that list is to make sure that the connection to the database is cleaned up properly: see the docs for the OleDbConnection[^] class for a small example of how to protect your connection. For the details about what it's doing read up on the using[^] statement.
|
|
|
|
|
Alright. Thanks for your answers. I think it will really help me a lot.
|
|
|
|
|
Glad to help
|
|
|
|
|
While a lot of folks will get mad at people "having others do their homework for them" you handled this very well. You attempted the code, had some problems and asked an intelligent question. You listened to advice, tried the solution and again did everything correct.
You did your best and this stuff is not easy at all. Don't give up and keep going, with your attitude you can do it.
Threads like these are part of why this place exists.
|
|
|
|
|
If you go to Visual Studio ->Tools -> Options you will see the tree view options on the left side and everey time you click on an item it will display a different options on the right side..
I want to know what's the bset way to do that? is it by different panels for every option (tree item) or by creating Tab contro and disable the headers or you have a better idea?
|
|
|
|
|
Easiest Method that I can think of:
Create different user controls. Whenever an item is selected in treeview, change the usercontrol displayed on the right side.
Save each control in a List<control> so that when "Save" button is clicked, each of these controls can save the info into their respective spaces.
|
|
|
|
|
Hi All, just a note before you start reading, I wanted to apologize in advance for going into so much detail but I wanted to be thorough... if perhaps confusing in places
OK, so whats happening is that I'm having trouble getting data to display when they are passed to a form.
What's meant to happen is that the form NotesWindow (form2) (which is initialized by the main form) is meant to initialize a third form NewNoteWindow (form3) which takes text input from the user and then passes it back to NotesWindow (form2) which is meant to display it in a listbox.
I have managed to, using a constructor pass the data from NewNoteWindow (form3) to NotesWindow (form2) but it will only display if I hide NotesWindow (form2) after getting it to open NewNoteWindow (form3) and then using NotesWindow.Show() from NewNoteWindow (form3) to bring up the form again.
My theory as to why this is happening is that I initialize NewNoteWindow (form3) from NotesWindow (form2) using NewNoteWindow newNoteWindow = new NewNoteWindow and then to pass the data back I need to initialize NotesWindow (form2) in NewNoteWindow (form3) using NotesWindow notesWindow = new NotesWindow I suspect that this is creating a new instance of NoteWindow (form2) and sending the data to that as opposed to the already open NotesWindow (form2).
If I'm right about that, anyone know how to send the data back to NotesWindow (form2) properly, if I'm wrong then anyone know what I'm doing wrong?
I'll include what I believe to be the relevant pieces of code at the bottom, if u want any more of the code or if you need me to clarify anything just ask.
Another problem I have had is that when I go to input a second piece of data the listbox is cleared of its data, I don't know if this is because of the this.hide() and NotesWindow.Show methods or because I'm initializing another instance of NotesWindow (form2) (I believe it's this reason) or something completely different.
Thanks in advance for any insight you can offer about my problem.
Relevant Code In NotesWindow (Form2)
NewNoteWindow newNoteWindow = new NewNoteWindow();
public string NewNote1
{
set
{
notesDisplayBox.Items.Add(value);
label1.Text = value;
}
}
private void addNewButton_Click(object sender, EventArgs e)
{
newNoteWindow.ShowDialog();
}
Relevant Code in NewNoteWindow (Form3)
public string NewNoteTextBox
{
get
{
return newNoteTextBox.Text;
}
}
private void okButton_Click(object sender, EventArgs e)
{
NotesWindow notesWindow = new NotesWindow(); <--- I initialize this here because if I do it
notesWindow.NewNote1 = NewNoteTextBox;
notesWindow.label1.Text = newNoteTextBox.Text;
this.Close();
}
Sorry again for making you read through all that, but I did want to be thorough.
Peace
|
|
|
|
|
your question is very very confusing. Could you please confirm this in a synopsis first?
What I gather is that
You open
form2 from form1.
form3 from form2
you want to pass data between forms.
there are a few methods to do this. these are:
1. when you open a form, you can pass parameters.
2. when you close the form, you can use properties to receive values from the closed forms.
3. if you want to pass the data while they are open, one of the most convenient methods is to have a static class, pass the values there. And add a eventhandler for every form when they come to focus.
4. write your own events and let the forms call events in other forms. Though this could be tricky with dialog mode forms. If you use Show(), it will work well.
Now, if you tell your problem in basic format, it would be easier to understand, your paragraph is really confusing to me atleast. may be others can understand better.
|
|
|
|
|
Yep that's right
from what you said there, I would need to use properties to pass data from form3 to form2 and use
parameters to pass date from form2 to form3.
The hierarchy of this is
form1 opens form2
form2 opens form3
form3 takes data from the user, then opens an instance of form2 and uses a constructor to pass the data back to form2 (I believe the problem lies here, thinking about whats happening, I believe this part is opening an instance of form2 that is not the instance that opened form3.
That is form2 opens form3, form3 opens form2a (as opposed to form2) if this makes any sense
Reading over what you posted, I believe the solution would be to use properties to receive the data when I close form3, what do you think?
|
|
|
|
|
exactly. Remember that when you open form2 from form1, both the forms are open. form1 is not closed or hidden.
so,when you open form2 again from form3, you cannot open a parent from a child. you must be opening a new instance which is different from original form2.
So, yes, you should allow form3 to take data from user, wait for user to click on OK button. if he clicks OK, send a dialogresult OK to form2. also, add a property in form3 which will then be accessed from form2.
I assume that there is no reason for form3 to be open after it has taken the data from user.
|
|
|
|
|
That's correct, the OK button also closes form3 immediately after it passes the data to form2.
I can understand what you mean, and it makes sense, but I don't know much about properties or passing data using a dialogresult if you know of any articles that explain this could you please link them.
When you say "add a property in form3 which will then be accessed from form2" do you mean have an object in form3 where I store the users input and then have form2 access the data and load it into itself as opposed to having form3 pass the data to form2?
|
|
|
|
|
form3:
class Form3:Form
{
private string m_data;
public string Data
{
get
{
return m_data;
}
set
{
m_data = value;
}
}
}
Assign the value of m_data to what you want to send to form2
Add two buttons in this form. set their dialogresult as OK and Cancel.
Form2:
Form3 form = new Form3();
if(form.ShowDialog() == DialogResult.OK)
{
string dataPassedFromForm3 = form.Data;
}
If your problem is sorted, rate the answer.
|
|
|
|
|
Thanks, solved the problem perfectly.
Just a follow up question if you don't mind, how would I pass data from form2 to form3 when its opened?
|
|
|
|
|
through constructor.
class Form3: Form
{
string dataReceived;
public Form3(string _dataToReceive)
{
dataReceived = _dataToReceive;
}
}
|
|
|
|
|
try this way for two forms if it what you want you can do it in three forms.
use delegation:
in form1 create button and textbox and put in the form:
public delegate void dd(string s);
public static dd d;
and put (d=new dd(write);) in public Form1()
then write method (write):
privet void write(string s)
{
textbox1.text=s;
}
in button put:
form2 f2=new form2();
f2.show();
in form2 create button and textbox then in click event put:
Form1.d(textbox1);
|
|
|
|
|
The easy way is to create a static class that contains the data you want to share between forms, and set/get the values for the various forms' controls using that static data.
.45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
How to change width of label that is AutoSize
(i mean autosize =true)
i wanna to grow the label in height but with unique width!
(the height must grow with the text that we will pass to label)
|
|
|
|
|
When in autosize, the height is calculated automatically and depends on the selected font, nothing else AFAIK.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that. [The QA section does it automatically now, I hope we soon get it on regular forums as well]
|
|
|
|
|
How can i have label with width = 243 and the hight grow upon the text we pass to it?
|
|
|
|
|
Griff and d@nish already answered that.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that. [The QA section does it automatically now, I hope we soon get it on regular forums as well]
|
|
|
|
|
The height of a label already depends on it's content. If you have a AutoSize label, then handing the label "Hello\nThere\nPaul" as the text will enlarge the height to fit the content. You cannot automatically make a label fixed width, with variable height - to implement this, you would have to set AutoSize to false, and use Graphics.MeasureString to determine the height required and manually set the label control height appropriately.
All those who believe in psycho kinesis, raise my hand.
My 's gonna unleash hell on your ass. tastic!
|
|
|
|
|
AFAIK you got two options:
1. Make use of Graphics.MeasureString method and insert "\n" whenever the width of text goes over the label width.
2. There is an article here at CP that shows creating vertical labels. You can customize that and change the text draw mode while keeping the way label grows in size same.
"No matter how many fish in the sea; it will be so empty without me." - From song "Without me" by Eminem
|
|
|
|
|
I didnt get anything and now i am confused!
Please Help
|
|
|
|
|
Graphics.MeasureString returns the approximate width that will be needed to display the text on screen. Now, you know the width of the label. So, you can get the width of the text you want to print in the label. Next, add "\n" at appropriate places so that the width of each line is less than that of the label.
In the second way, you need to search the CP article for vertical labels. The only difference in that label and the one you need is the way text is displayed in the label. So. just change that and you should be done.
"No matter how many fish in the sea; it will be so empty without me." - From song "Without me" by Eminem
|
|
|
|
|
No ans!!!!!!!!!!!!!!!!!!!!!!!!1
|
|
|
|