双击GridView时如何显示将所选数据显示到表单中
我使用Devexpress GridControl来显示数据库中的员工数据,
这里员工形式
private void Employee_Load(object sender, EventArgs e)
{
String strProvider = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source= C:UsersJohnDocumentsSistem Informasi Akuntansi.accdb";
string query = "SELECT EmployeeCode, FirstName, LastName, FullName, JoinDate, EffectiveDate, Address, PhoneNumber, DateofBirth, PlaceofBirth, Email, Gender, Religion, Nationality FROM Employee";
OleDbConnection con = new OleDbConnection(strProvider);
OleDbCommand cmd = new OleDbCommand(query, con);
con.Open();
cmd.CommandType = CommandType.Text;
OleDbDataAdapter da = new OleDbDataAdapter(cmd);
DataTable employee = new DataTable();
da.Fill(employee);
view_employee.DataSource = employee;
}
它将在下面显示为预览
当我双击任何一行时,我想让它显示带有我选择的数据的A Form,这里是我的DoubleClick事件
private void gridView1_DoubleClick(object sender, EventArgs e)
{
edit_employee editdata = new edit_employee();
editdata.ShowDialog();
在这里我的edit_employee表单
private void edit_employee_Load(object sender, EventArgs e)
{
OleDbCommand command = new OleDbCommand("SELECT EmployeeCode, FirstName, LastName, FullName, JoinDate, EffectiveDate, Address, PhoneNumber, DateofBirth, PlaceofBirth, Email, Gender, Religion, Nationality FROM Employee WHERE Employee.Id = 57"); //must use parameter
command.Connection = connection;
OleDbDataReader dr = null;
connection.Open();
dr = command.ExecuteReader();
while (dr.Read())
{
employee_code.Text = (dr["EmployeeCode"].ToString());
txtfirstname.Text = (dr["FirstName"].ToString());
txtlastname.Text = (dr["LastName"].ToString());
txtfullname.Text = (dr["FullName"].ToString());
joindate.Text = (dr["JoinDate"].ToString());
effectivedate.Text = (dr["EffectiveDate"].ToString());
address.Text = (dr["Address"].ToString());
phonenumber.Text = (dr["PhoneNumber"].ToString());
dateofbirth.Text = (dr["DateofBirth"].ToString());
placeofbirth.Text = (dr["PlaceofBirth"].ToString());
email.Text = (dr["Email"].ToString());
gender.Text = (dr["Gender"].ToString());
religion.Text = (dr["Religion"].ToString());
nationality.Text = (dr["Nationality"].ToString());
}
connection.Close();
}
下面的表单将在我DoubleClick任何行后显示
因为我用查询过滤数据“WHERE Employee.Id = 57”我知道用单击的数据显示表单,我不应该像这样过滤(必须使用参数过滤),但我不知道如何过滤来自我选择的行的参数。
任何解决方案将非常感激。
链接地址: http://www.djcxy.com/p/31057.html上一篇: How to show get selected data into form when double click on GridView
下一篇: How to save and reload the state of the dxdatagrid component the angular way