Tuesday, July 14, 2009

I want to Input into textbox from other opened form. How Can I do that into C#.Net 2005 winform?

Hello All you great Pro


I was developing applications in VB6 and Converting myself into C#.Net. But I got trouble in one thing





I have a form for select certain field in C#.Net. When I pressed on that field to enter select option such as ... I want to search on PinCode in a text box. When I press enter in that TextBox it will open a new form with list of PinCode from Database. When I select the PinCode from the List and Click on the Ok But of other form the PinCode will palce in TextBox of Searching Form(Mean Cross Form Value Exchange/One Form to another form data exchange).





I was doing it in VB6 very easily.





Please help me How can I do that





thanks in Advance

I want to Input into textbox from other opened form. How Can I do that into C#.Net 2005 winform?
Create a public property on Form1 that wraps the textbox you are using (replace textBox1 with the name of your textbox):





public string PinCode


{


get { return textBox1.Text; }


set { textBox1.Text = value; }


}





Then, open Form2 using ShowDialog:





Form2 pinForm = new Form2();


pinForm.ShowDialog(this);





I assume that Form2 has a listbox and a button. I recommend making this a fixed dialog. You'll need to wire the button click, listbox double-click, and Form Load events, cut and paste will probably not work. Here is Form2 Code:





using System;


using System.Collections.Generic;


using System.ComponentModel;


using System.Data;


using System.Drawing;


using System.Text;


using System.Windows.Forms;





namespace CrossForm


{


public partial class Form2 : Form


{


private Form1 CallingForm = null;





public Form2()


{


InitializeComponent();


}





private void button1_Click(object sender, EventArgs e)


{


ItemSelected();


}





private void Form2_Load(object sender, EventArgs e)


{


// Check the owner of the form


if (this.Owner is Form1)


{


CallingForm = (Form1)this.Owner;





// Do database stuff here and bind the results to listBox1


listBox1.SelectedIndex = listBox1.FindStringExact ( CallingForm.PinCode );


}


}





private void listBox1_DoubleClick(object sender, EventArgs e)


{


ItemSelected();


}





private void ItemSelected()


{


// Only do this if Form1 owns the form and there is an item selected


if (CallingForm != null %26amp;%26amp; listBox1.SelectedItem != null)


{


CallingForm.PinCode = listBox1.SelectedItem. ToString();


}


this.Close();


}





}


}
Reply:I'm not sure I understand the question: I'm going to take a stab at it, If I'm incorrect or you need more help, then feel free to email me at irishtek@yahoo.com





I undersand: you have a form option the user can select from that should open another form with a list of information. The user can select from this information and based upon the selection will populate some other field in the first form?





I'd recomned using panels. form1 on panel1 form2 on panel2


when option is selected in form1 the code behind can make form1 invisible and form2 visible





Then once the selection is made on form2 the form1 can be made visible and populated with the selection from form2, then form2 can be made invisible.

innia

No comments:

Post a Comment