passing data
-
I am a newbie, and I am starting to use the C# language, and I need a little help. Here goes: Main Form: I put a textbox where card number should be inputted. When the user presses the Enter key it should look into the database (table) the value of the textbox. Condition is: If only one (1) item found, the information will be displayed on the Main Form other textboxes. Otherwise if two or more items found, it will pass the card number to Form 2. Form 2: will be shown if Main Form calls Receive the card number passed by Main Form and search again the database (table) and display the items found on the datagridview. Then the user should select one (1) item, and pass back the single item with the complete (full) card number selected on the Main Form. My questions: How will I get the value of the current cell that I selected? How will I pass back the value I selected to the Main Form? How will Main Form receive the data being passed by Form 2? Many thanks! Form 1: public partial class MRRMainForm : Form { // start partial class MRRMainForm public String myConString = @"Provider=VFPOLEDB.1;" + @"Data Source=" + D:\\MyMaintable.DBF"; public String cardNumber; OleDbConnection con; OleDbDataAdapter da; OleDbCommand cmd = new OleDbCommand(); DataSet ds = new DataSet(); String commandSearch; public MRRMainForm() { InitializeComponent(); } private void txtCardNumber_KeyDown(object sender, KeyEventArgs e) { switch (e.KeyCode) { // will trap other keys later.. //case Keys. // break; case Keys.Enter: findCardNumber(); txtDescription.Focus(); break; } // end switch } private void findCardNumber() { commandSearch = "Select * from MyMaintable where substr(prod_code,6,7)=\"" + txtCardNumber.Text + "\""; con = new OleDbConnection(myConString); cmd.CommandText = commandSearch; cmd.Connection = con; con.Open(); cmd.ExecuteNonQuery(); da = new OleDbDataAdapter(cmd); da.Fill(ds); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows.Count > 1) {
-
I am a newbie, and I am starting to use the C# language, and I need a little help. Here goes: Main Form: I put a textbox where card number should be inputted. When the user presses the Enter key it should look into the database (table) the value of the textbox. Condition is: If only one (1) item found, the information will be displayed on the Main Form other textboxes. Otherwise if two or more items found, it will pass the card number to Form 2. Form 2: will be shown if Main Form calls Receive the card number passed by Main Form and search again the database (table) and display the items found on the datagridview. Then the user should select one (1) item, and pass back the single item with the complete (full) card number selected on the Main Form. My questions: How will I get the value of the current cell that I selected? How will I pass back the value I selected to the Main Form? How will Main Form receive the data being passed by Form 2? Many thanks! Form 1: public partial class MRRMainForm : Form { // start partial class MRRMainForm public String myConString = @"Provider=VFPOLEDB.1;" + @"Data Source=" + D:\\MyMaintable.DBF"; public String cardNumber; OleDbConnection con; OleDbDataAdapter da; OleDbCommand cmd = new OleDbCommand(); DataSet ds = new DataSet(); String commandSearch; public MRRMainForm() { InitializeComponent(); } private void txtCardNumber_KeyDown(object sender, KeyEventArgs e) { switch (e.KeyCode) { // will trap other keys later.. //case Keys. // break; case Keys.Enter: findCardNumber(); txtDescription.Focus(); break; } // end switch } private void findCardNumber() { commandSearch = "Select * from MyMaintable where substr(prod_code,6,7)=\"" + txtCardNumber.Text + "\""; con = new OleDbConnection(myConString); cmd.CommandText = commandSearch; cmd.Connection = con; con.Open(); cmd.ExecuteNonQuery(); da = new OleDbDataAdapter(cmd); da.Fill(ds); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows.Count > 1) {
Maybe look at a public method on form2 as your entry point from form1, in that public method you use as the entry point use a ref variable that will enable you to use the variable in form2 and what ever you changed it to in form2 it will return that value back to form1.
He who laughs last is a bit on the slow side
-
I am a newbie, and I am starting to use the C# language, and I need a little help. Here goes: Main Form: I put a textbox where card number should be inputted. When the user presses the Enter key it should look into the database (table) the value of the textbox. Condition is: If only one (1) item found, the information will be displayed on the Main Form other textboxes. Otherwise if two or more items found, it will pass the card number to Form 2. Form 2: will be shown if Main Form calls Receive the card number passed by Main Form and search again the database (table) and display the items found on the datagridview. Then the user should select one (1) item, and pass back the single item with the complete (full) card number selected on the Main Form. My questions: How will I get the value of the current cell that I selected? How will I pass back the value I selected to the Main Form? How will Main Form receive the data being passed by Form 2? Many thanks! Form 1: public partial class MRRMainForm : Form { // start partial class MRRMainForm public String myConString = @"Provider=VFPOLEDB.1;" + @"Data Source=" + D:\\MyMaintable.DBF"; public String cardNumber; OleDbConnection con; OleDbDataAdapter da; OleDbCommand cmd = new OleDbCommand(); DataSet ds = new DataSet(); String commandSearch; public MRRMainForm() { InitializeComponent(); } private void txtCardNumber_KeyDown(object sender, KeyEventArgs e) { switch (e.KeyCode) { // will trap other keys later.. //case Keys. // break; case Keys.Enter: findCardNumber(); txtDescription.Focus(); break; } // end switch } private void findCardNumber() { commandSearch = "Select * from MyMaintable where substr(prod_code,6,7)=\"" + txtCardNumber.Text + "\""; con = new OleDbConnection(myConString); cmd.CommandText = commandSearch; cmd.Connection = con; con.Open(); cmd.ExecuteNonQuery(); da = new OleDbDataAdapter(cmd); da.Fill(ds); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows.Count > 1) {
1. For the first task, you can capture any suitable event of the DataGridView in which you can get the content of the selected cell like CellClick etc 2. To pass back the data to MainForm There are many ways to do it. I choose the simplest one. Create public properties in Second form and while closing this form, set the values of those properties with the selected values. 3. To get the data passed from form2 When the form2 closes, read the public properties created in step2
-
I am a newbie, and I am starting to use the C# language, and I need a little help. Here goes: Main Form: I put a textbox where card number should be inputted. When the user presses the Enter key it should look into the database (table) the value of the textbox. Condition is: If only one (1) item found, the information will be displayed on the Main Form other textboxes. Otherwise if two or more items found, it will pass the card number to Form 2. Form 2: will be shown if Main Form calls Receive the card number passed by Main Form and search again the database (table) and display the items found on the datagridview. Then the user should select one (1) item, and pass back the single item with the complete (full) card number selected on the Main Form. My questions: How will I get the value of the current cell that I selected? How will I pass back the value I selected to the Main Form? How will Main Form receive the data being passed by Form 2? Many thanks! Form 1: public partial class MRRMainForm : Form { // start partial class MRRMainForm public String myConString = @"Provider=VFPOLEDB.1;" + @"Data Source=" + D:\\MyMaintable.DBF"; public String cardNumber; OleDbConnection con; OleDbDataAdapter da; OleDbCommand cmd = new OleDbCommand(); DataSet ds = new DataSet(); String commandSearch; public MRRMainForm() { InitializeComponent(); } private void txtCardNumber_KeyDown(object sender, KeyEventArgs e) { switch (e.KeyCode) { // will trap other keys later.. //case Keys. // break; case Keys.Enter: findCardNumber(); txtDescription.Focus(); break; } // end switch } private void findCardNumber() { commandSearch = "Select * from MyMaintable where substr(prod_code,6,7)=\"" + txtCardNumber.Text + "\""; con = new OleDbConnection(myConString); cmd.CommandText = commandSearch; cmd.Connection = con; con.Open(); cmd.ExecuteNonQuery(); da = new OleDbDataAdapter(cmd); da.Fill(ds); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows.Count > 1) {
Just have the MultiplesFound form expose a public property indicating the row that was selected by the user.
if (ds.Tables[0].Rows.Count > 0) { //Used if there is only one Row returned. int SelectedRow = 0; if (ds.Tables[0].Rows.Count > 1) { cardNumber = txtCardNumber.Text; MultiplesFound myMF = new MultiplesFound(cardNumber); myMF.myCardNumber = cardNumber; myMF.ShowDialog(); //Retrieve the row selection SelectedRow = myMF.SelectedRow; } //Display the selected Row (or first row when only one has been returned txtProductCode.DataBindings.Add("text", ds.Tables[SelectedRow], "prod_code"); txtDescription.DataBindings.Add("text", ds.Tables[SelectedRow], "prod_desc"); txtModelNumber.DataBindings.Add("text", ds.Tables[SelectedRow], "model_no"); }
Jeff Clark Systems Architect JP Clark, INC. Columbus, Ohio