Could someone help me with my problem here? I am using C# and working on a project in visual studio 2008 with SQL server express as the database. In visual studio 2008, I have a project and two forms. The first form that is named 'Informations' has a single datagridview included. I populated the datagridview by selecting all fields in my table in SQL and then binded it to a dataset.
SqlCommand cmd = new SqlCommand("select * from myTable", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
myDataGridview.DataSource = ds.Tables[0];
The table myTable is consist of three columns namely 'ID', 'LastName', 'FirstName'.. Using the code above I successfully binded the dataset to the datagridview named 'myDataGridview'.
The second form that is named 'PassedInformations" has three textbox. I have used the constructor method to pass the selected values from form Information's datagridview to form PassedInformation's three textbox.
string txtbox1 = myDataGridview.CurrentRow.Cells[0].Value.ToString();
string txtbox2 = myDataGridview.CurrentRow.Cells[1].Value.ToString();
string txtbox3 = myDataGridview.CurrentRow.Cells[2].Value.ToString();
//show PassedInformations and fill the textboxes with datagridview's selected value
PassedInformation information = new PassedInformation(txtbox1, txtbox2, txtbox3)
information.ShowDialog();
Then in form PassedInformation I place the passed string to the constructor method.
All works well but I was suddenly required by my professor to only show the 'Last Name' and 'First Name' column in myDataGridview but still capable of passing the values of 'ID', 'Last Name' and 'First Name'.
I think I need to passed columns of dataset instead the datagridview because the values that would be pass dependeds to the selected row/cell of myDataGridview, but the fact that a column is not present and still required to be pass is quite improbable to me. How could I determine the selected value of the datagridview then still pass the 'ID' which is not present in myDataGridview.