hi,
I have 3 forms. In form1 I have a textbox and a button. On button click the form1 should close and a new form(form2)should open and in form2 I have a textbox and a button immediate after the textbox1.That textbox1 in form2 shows the value that is passed through the form1's textbox.It can be achieved by the overloaded constructor. But if I click on the button in the form2 it should take into the datagridview containing form(form3) and in that there are few tuples. (id,name,addrs,sex,zip,city,etc) Now if I select a particular row(mouse single click) then it should pick the name attribute and go back to the form2 and display the name in the textbox1 of form2. How to get this??
Vimal KandasamyPosted Apr 16, 2009, 12:18 AM
I hope you know what to do till form2 opens...
Let me continue after that...
form2 to form3
in button click
Form3 f = new Form3(this);
f.ShowDialog();
then in form3 add the following code...
//constructor
Form2 form2;
public Form3(Form2 f)
{
InitializeComponent();
this.form2 = f;
}
//for datagrid
{try this...
Note : modifiers property of TextBox1 of form2 set to public
Vimal KandasamyPosted May 8, 2009, 9:21 AM
follow link and see my reply.
Two forms and one datagrid
It shows you how to access datagrid in another form.then you can retrieve rows one by one and write it using stream writer.
abhishek kaushalPosted May 8, 2009, 9:03 AM
Sorry to interrupt u guys . if u guys don't mind I've a problem similar to this. i need to write a windows form application which reads data from a textfile to a datagrid and then write it to a textfile with certain changes.
the user should be able to delete or update rows and can have output of selected rows.
i have been able to get the data from a textfile to datagrid. and now i want it in a textfile..so i have a datgrid on form 2 and i when i click on a button in form 3 the program should write a data to a textfile.
your help will be much appreciated..
regards
abhi
sachi vasishtaPosted Apr 16, 2009, 8:34 AM
yes vimal it worked fine. The thing I noticed is when i went to events in MouseClick dataGridView1_MouseClick it was not pointing i dont know why it happened is it beacause i copied the code
private void datagridview1_Mouseclick(...,....) from a notepad?? anyway thank you very much.
vimal now I have a form which contains a datagridview control and a button called "Edit mode".In form1 I will retrieve some/all info from mysql database table `insurance`(assume there are 8 columns in the table insurance) and display it on the datagrid view. In datagridview the data will be shown from the first row itself. Now what I want is if the user clicks the “Edit Mode” button for adding a new entry, the first row of the table should provide the columns for entering the details of the table insurance. And also in datagridview when I select a particular row then the col'0',col'1', and col'2' values should be placed to the textboxes of other form say form2(the form1 should be closed).How to achieve this. Please help!
Thanks
Vimal KandasamyPosted Apr 16, 2009, 8:07 AM
then i think, you didn't set MouseClick event of dataGridview1 properly..
Make sure it in dataGridview Properities ->Open Events
verify
MouseClick points dataGridView1_MouseClick
put breakpoint inside MouseClick event of DataGridView
and verify whether cell content is assigned to Textbox1 of form2 while you click on DataGridView1
Verify and tel me..
SreekanthPosted Apr 16, 2009, 8:02 AM
i think u dont like window.close() in javascript
by using Response.redirect u will get required open/close.
in data grid use item template column eg:edit/del columns
and on event click of that again redirect ur previous ie 1 form with grid data ROW(e.item.cells[i].text) using viewstate or qrystring or !session[]
sachi vasishtaPosted Apr 16, 2009, 7:59 AM
Vimal KandasamyPosted Apr 16, 2009, 7:40 AM
(//Form9.ActiveForm.Close();)
Continue debugging...
we will clear that later...
sachi vasishtaPosted Apr 16, 2009, 7:26 AM
vimal I put some break points and started debugging and in
Form9.ActiveForm.Close(); inside the form10_load method that i had sent you there is an exception like this
NullReferenceException was unhandled
Object reference not set to an instance of an object.
Vimal KandasamyPosted Apr 16, 2009, 6:03 AM
I don't know what happened in yours application... Have you check it by debugging[ put some breakpoints & press F11]...check it and tel me
Is there any warnings?...
Have you set Modifiers as public?...
For Combobox
you simply set AutoCompleteMode =Suggest or SuggestAppend
and
AutoCompleteSource=ListItems...
It will bring the list
please verify and update soon
sachi vasishtaPosted Apr 16, 2009, 4:54 AM
Vimal I tried with the code you sent but when i click on the row of a datagridview(form3) the selected rows content is not placed into the textbox of form2 instead it is showing the value I passed through the constructor of form1.I will send you the code I have typed. Vimal also in a combobox containing states when i press a character say 't' it takes me to the state name that starts with t but if i keep on pressing the t it should take me to the next.How to do this
/* form9(form1 in my question) */
private
void button1_Click(object sender, EventArgs e){
Form10 recepinsurance = new Form10(fname2);recepinsurance.Show();
}
/* form10(form2 in my question) */
public partial class Form10 : Form{
public Form10(string fname3){
InitializeComponent();
textBox1.Text = fname3;
}
private void button1_Click(object sender, EventArgs e){
Form13 recpriinsu = new Form13(this);recpriinsu.ShowDialog();
}
/* form13(form 3 in my question) */
public partial class Form13 : Form{
Form10 form10; public Form13(Form10 f1){
InitializeComponent();
this.form10 = f1;}
private void Form13_Load(object sender, EventArgs e){
OdbcConnection oConnection = new OdbcConnection("Dsn=Medoffice"); /* connection for responsibleparty table */oConnection.Open();
OdbcCommand oCommand = new OdbcCommand();oCommand.Connection = oConnection;
oCommand.CommandText =
string.Format("select partyid, firstname, lastname, middleinit as minit, city, state, mobilephone, emailid, address, zipcode, ssn, homephone, workphone, employer from responsibleparty"); OdbcDataAdapter da = new OdbcDataAdapter(oCommand); DataTable insuredparty = new DataTable();da.Fill(insuredparty);
dataGridView1.DataSource = insuredparty;
oConnection.Close();
}
private void dataGridView1_MouseClick(object sender, MouseEventArgs e){
DataGridViewRow dr = dataGridView1.CurrentRow;form10.textBox1.Text = dr.Cells[1].Value.ToString();
/* copy 2nd cell of row into string var "user" */ this.Dispose();}
}
sachi vasishtaPosted Apr 15, 2009, 8:12 AM
SreekanthPosted Apr 15, 2009, 7:21 AM
ur platform?
if( c#.net) i can help u..