Click here to Skip to main content
15,892,059 members
Home / Discussions / C#
   

C#

 
AnswerRe: data transfers between two forms Pin
Blue_Boy12-Oct-10 22:39
Blue_Boy12-Oct-10 22:39 
GeneralRe: data transfers between two forms PinPopular
OriginalGriff12-Oct-10 22:44
mveOriginalGriff12-Oct-10 22:44 
GeneralRe: data transfers between two forms Pin
Blue_Boy12-Oct-10 22:48
Blue_Boy12-Oct-10 22:48 
AnswerRe: data transfers between two forms Pin
OriginalGriff12-Oct-10 22:41
mveOriginalGriff12-Oct-10 22:41 
GeneralRe: data transfers between two forms Pin
Erdinc2712-Oct-10 22:46
Erdinc2712-Oct-10 22:46 
GeneralRe: data transfers between two forms PinPopular
OriginalGriff12-Oct-10 23:00
mveOriginalGriff12-Oct-10 23:00 
GeneralRe: data transfers between two forms Pin
Erdinc2712-Oct-10 23:23
Erdinc2712-Oct-10 23:23 
AnswerRe: data transfers between two forms PinPopular
Pete O'Hanlon12-Oct-10 23:06
mvePete O'Hanlon12-Oct-10 23:06 
It always amazes me that people try to write the most tortuous logic to communicate between two disparate items in an application when there are mechanisms built into the framework that allow you to do this with ease. Consider the problem if you want to do this with a modeless form; you want to one form to be able to respond to something that happened in another form; can you think of a mechanism that allows you to communicate in this fashion? I am, of course, talking about using events here.

Now, in your case, there is an even simpler way to achieve this. When you create an instance of Form2 (that's not a good name by the way, your naming convention should always indicate the intent of the item you are naming), you then display it using ShowDialog. This means that processing in Form1 halts until Form2 returns control to it - this, of course, means that you have access to the properties and methods inside Form2 until you Dispose of it. What you should do, in Form2, is create public properties that expose the values inside the textboxes and, once control has been returned to Form1, you should then take the values from it. Here's one way to code it:
private void btnRehber_Click(object sender, EventArgs e)
{
  using (Form2 rhbForm = new Form2()) // Please rename Form2.
  {
    // It's good practice to Dispose of forms. By wrapping
    // this in a using block, the form will be disposed of
    // automatically.
    rhbForm.txtYetkili_isim.Text = txtYetkili_adi.Text;
    if (rhbForm.ShowDialog() == DialogResult.OK)
    {
      // Only update the fields if the user clicked OK.
      txtGsm1.Text = rhbForm.Gsm1;
      txtGsm2.Text = rhbForm.Gsm2;
      frmFirma.txtNumara.Text = rhbForm.Numara;
    }
  }
}
Then, in Form2, I'd create Gsm1, Gsm2 and Numara as public (or internal) readonly properties which simply wrap access to the relevant textboxes.

I have CDO, it's OCD with the letters in the right order; just as they ruddy well should be

Forgive your enemies - it messes with their heads


My blog | My articles | MoXAML PowerToys | Onyx


GeneralRe: data transfers between two forms Pin
Erdinc2712-Oct-10 23:24
Erdinc2712-Oct-10 23:24 
GeneralRe: data transfers between two forms Pin
Pete O'Hanlon12-Oct-10 23:29
mvePete O'Hanlon12-Oct-10 23:29 
GeneralRe: data transfers between two forms Pin
fjdiewornncalwe13-Oct-10 1:35
professionalfjdiewornncalwe13-Oct-10 1:35 
GeneralRe: data transfers between two forms Pin
Jason Henderson14-Oct-10 3:41
Jason Henderson14-Oct-10 3:41 
AnswerRe: data transfers between two forms Pin
Ashutosh kumar Tripathi17-Oct-10 19:56
Ashutosh kumar Tripathi17-Oct-10 19:56 
Questionproblem with AL.exe created DLL Pin
prasadbuddhika12-Oct-10 18:13
prasadbuddhika12-Oct-10 18:13 
AnswerRe: problem with AL.exe created DLL Pin
fjdiewornncalwe13-Oct-10 2:37
professionalfjdiewornncalwe13-Oct-10 2:37 
QuestionSpace as string in user settings file Pin
cbutle3@netzero.com12-Oct-10 5:24
cbutle3@netzero.com12-Oct-10 5:24 
AnswerRe: Space as string in user settings file Pin
#realJSOP12-Oct-10 8:07
mve#realJSOP12-Oct-10 8:07 
AnswerRe: Space as string in user settings file Pin
kevinnicol12-Oct-10 8:25
kevinnicol12-Oct-10 8:25 
GeneralRe: Space as string in user settings file Pin
cbutle3@netzero.com12-Oct-10 9:01
cbutle3@netzero.com12-Oct-10 9:01 
GeneralRe: Space as string in user settings file Pin
Ian Shlasko12-Oct-10 9:33
Ian Shlasko12-Oct-10 9:33 
AnswerRe: Space as string in user settings file [modified] Pin
PIEBALDconsult12-Oct-10 17:09
mvePIEBALDconsult12-Oct-10 17:09 
QuestionDataGridView Search [modified] Pin
boreland12-Oct-10 3:55
boreland12-Oct-10 3:55 
AnswerRe: DataGridView Search Pin
Luc Pattyn12-Oct-10 4:14
sitebuilderLuc Pattyn12-Oct-10 4:14 
GeneralRe: DataGridView Search Pin
boreland12-Oct-10 4:19
boreland12-Oct-10 4:19 
GeneralRe: DataGridView Search Pin
Luc Pattyn12-Oct-10 4:43
sitebuilderLuc Pattyn12-Oct-10 4:43 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.