I am creating an app that connects to an Access DB for tracking Job Costing. I am creating the app to keep individuals out of the DB as much as possible. I have already created forms, Reports, Queries and such in the DB and am not stepping out of the DB to limit user interaction with the DB and access to information contained in the DB. I have already setup 1 part of the app for adding information and am now creating the next step which is for editing specific items in the DB. I have a form that the user selects an employee and Date to search for within the DB and the specific information from the query becomes visible for the user. I am next adding a button on the end of each row for the user to select a button on a row so they can edit the information.
This has worked fine so far but now am having trouble getting the button information so I know which button has been pushed. Here is the part where the DataGridView is created, the dataset displayed in the DataGridView and then a button added to each row.
private void buttonSearch_Click(object sender, EventArgs e)
{
//rowIndex = 0;
searchEmployee = comboBoxEmployeeSearch.SelectedValue.ToString();
searchWorkDate = dateTimePickerWorkDate.Value.ToString("M/d/yyyy");
string stSql = "SELECT tblJobCosting.Employee, tblJobCosting.WorkDate, tblJobCosting.JobCode, tblJobCosting.Task, tblJobCosting.BoxBatchNumber, tblJobCosting.StartTime, tblJobCosting.StopTime, tblJobCosting.StartDoc, tblJobCosting.EndDoc FROM tblJobCosting WHERE (((tblJobCosting.Employee)='" + searchEmployee + "') AND ((tblJobCosting.[WorkDate])=#" + searchWorkDate + "#));";
var conn = new OleDbConnection(connStr1);
conn.Open();
var cmd1 = new OleDbCommand(stSql, conn);
OleDbDataAdapter dAdapter = new OleDbDataAdapter(cmd1);
DataSet dSet = new DataSet();
dAdapter.Fill(dSet);
dgvJCSearchResults.DataSource = dSet.Tables[0];
conn.Close();
dgvJCSearchResults.Font = new System.Drawing.Font("Microsoft Sans Serif", 12);
dgvJCSearchResults.Columns["StartTime"].DefaultCellStyle.Format = "hh:ss tt";
dgvJCSearchResults.Columns["StopTime"].DefaultCellStyle.Format = "hh:ss tt";
dgvJCSearchResults.Show();
dgvJCSearchResults.Visible = true;
dgvJCSearchResults.AutoResizeColumns();
dgvJCSearchResults.AutoSize = true;
//MakeRowsUneditable();
DataGridViewButtonColumn btn = new DataGridViewButtonColumn();
dgvJCSearchResults.Columns.Add(btn);
btn.HeaderText = "Click Edit";
btn.Text = "Edit";
btn.Name = "btn";
btn.UseColumnTextForButtonValue = true;
}
private void MakeRowsUneditable()
{
foreach(DataGridViewRow r in dgvJCSearchResults.Rows)
{
r.ReadOnly = true;
}
}
private void EditRow(DataGridViewRow r)
{
r.ReadOnly = false;
}
private void dgvJCSearchResults_CellClick(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex == 3)
{
MessageBox.Show((e.RowIndex + 1) + " Row " + (e.ColumnIndex + 1) + " column Button Clicked JC");
}
}
private void btn_Click(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex == 3)
{
MessageBox.Show((e.RowIndex + 1) + " Row " + (e.ColumnIndex + 1) + " column Button Clicked btn");
}
}
private void DataGridViewButtonColumn_CellClick(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex == 3)
{
MessageBox.Show((e.RowIndex + 1) + " Row " + (e.ColumnIndex + 1) + " column Button Clicked dgv");
}
}
private void DataGridViewButtonCell_CellClick(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex == 3)
{
MessageBox.Show((e.RowIndex + 1) + " Row " + (e.ColumnIndex + 1) + " column Button Clicked dgv");
}
}
}
}
Where am I going wrong and how do I fix it? Help please!!