hello!
when i click the datagrid, how can i view the current selection
pls. see attached jpeg
tnx.
Printable View
hello!
when i click the datagrid, how can i view the current selection
pls. see attached jpeg
tnx.
Asuming that myDataTable is bound to myDataGrid:You can also get it through a BindingContext and CurrencyManager but I've never actually done that so I'll leave that to someone else to demonstrate, or you could search the forum for existing examples.C# Code:
DataRowView row = myDataTable.DefaultView(myDataGrid.CurrentRowIndex);
i've done this in VS2005 its easy as this:
private void dataGridView1_Navigate(object sender, System.Windows.Forms.NavigateEventArgs ne)
{
try
{
DateTime dt = DateTime.Parse(dataGridView1.CurrentCell.ColumnNumber["DATE_HIRED"].Value.ToString());
txtEmpID.Text = dataGridView1.CurrentRow.Cells["EMP_NUMBER"].Value.ToString();
txtLname.Text = dataGridView1.CurrentRow.Cells["LAST_NAME"].Value.ToString();
txtFname.Text = dataGridView1.CurrentRow.Cells["FIRST_NAME"].Value.ToString();
txtMI.Text = dataGridView1.CurrentRow.Cells["MID_NAME"].Value.ToString();
mskDateHired.Text = dt.ToString("MM/dd/yyyy");
cboSectionCode.Text = dataGridView1.CurrentRow.Cells["ORG_SECTION_CODE"].Value.ToString();
btnEdit.Enabled = true;
txtEmpID.Enabled = false;
txtFname.Enabled = false;
txtLname.Enabled = false;
txtMI.Enabled = false;
mskDateHired.Enabled = false;
cboSectionCode.Enabled = false;
btnSave.Enabled = false;
btnDelete.Enabled = true;
}
catch
{
return;
}
}
but in VS2003 its different approach
It's got nothing to do with 2003 and 2005. It's got to do with the fact that the DataGridView and DataGrid are two different controls. What's the problem with what I suggested previously?
ok, for now i solved my own problem tnx anyways.
pls. see code below
private void dataGridView1_CurrentCellChanged(object sender, System.EventArgs e)
{
dataGridView1.Refresh();
int iRownr=this.dataGridView1.CurrentCell.RowNumber;
int iColnr=this.dataGridView1.CurrentCell.ColumnNumber;
object cellvalue1=this.dataGridView1[iRownr, iColnr];
object cellvalue2=null;
object cellvalue3=null;
object cellvalue4=null;
object cellvalue5=null;
object cellvalue6=null;
try
{
cellvalue2=dataGridView1[iRownr, iColnr+1];
cellvalue3=dataGridView1[iRownr, iColnr+2];
cellvalue4=dataGridView1[iRownr, iColnr+3];
DateTime MyDate = DateTime.Parse(dataGridView1[iRownr, iColnr+4].ToString());
cellvalue5 = MyDate.ToString("MM/dd/yyyy");
cellvalue6=dataGridView1[iRownr, iColnr+6];
txtEmpID.Text=cellvalue1.ToString();
txtLname.Text=cellvalue2.ToString();
txtFname.Text= cellvalue3.ToString();
txtMI.Text=cellvalue4.ToString();
mskDateHired.Text=cellvalue5.ToString();
cboSectionCode.Text=cellvalue6.ToString();
}
catch
{
MessageBox.Show("Please don't click the column, if you want to change the data click the pointer or \n search again to navigate the data.","Unexpected Error",MessageBoxButtons.OK,MessageBoxIcon.Error);
}
}
Are you determined to ignore my previous suggestion for some reason?vb Code:
DataRowView row = myDataTable.DefaultView[myDataGrid.CurrentRowIndex]; txtEmpID.Text = (string)row["EmpID"]; // etc.
DataTable myDataTable = (DataTable) dataGridView1.DataSource;
DataRowView row = myDataTable.DefaultView[dataGridView1.CurrentRowIndex];
MessageBox.Show((string)row["EMP_NUMBER"]);
tnx a lot it works!