双击dataGridView后的数据传递示例
来源:互联网 发布:spf算法 编辑:程序博客网 时间:2024/05/29 03:05
该示例实现的功能为:
点击form1窗体上的comboBox下拉列表框然后弹出一个form2窗体,form2窗体上有一个dataGridView1,然后双击dataGridView1的某一行数据,会把选中的该行数据传递到form1,并自动填充form1中的comboBox和textbox.
form2窗体中的主要事件代码为:
点击form1窗体上的comboBox下拉列表框然后弹出一个form2窗体,form2窗体上有一个dataGridView1,然后双击dataGridView1的某一行数据,会把选中的该行数据传递到form1,并自动填充form1中的comboBox和textbox.
form2窗体中的主要事件代码为:
//填充dataGridView1
public void datalist()
{
string mysql = "select papertypes as 用纸类型,len as 长,wid as 宽,ke as 克重,xishu as 系数,dprice as 吨价,lprice as 令价 from system_paperprice";
DataSet grid = new DataSet();
string connectionString = ConfigurationManager.ConnectionStrings["进销存管理系统.Properties.Settings.ld_ysglConnectionString"].ConnectionString;
SqlConnection myConnection = new SqlConnection(connectionString);
myConnection.Open();
grid.Clear();
SqlDataAdapter myda = new SqlDataAdapter(mysql, myConnection);
myda.Fill(grid);
dataGridView1.DataSource = grid.Tables[0];
myConnection.Close();
}
//双击选择用纸类型信息并回送到调用的窗体-------------
private void dataGridView1_DoubleClick(object sender, System.EventArgs e)
{
if (this.dataGridView1.ReadOnly == true)
{
int intCurrentRowNumber = this.dataGridView1.CurrentCell.RowIndex;
string sendStokername, sendStokerdprice, sendStokerke, sendStokerxishu, sendStokerlprice;
sendStokername = this.dataGridView1.Rows[intCurrentRowNumber].Cells[0].Value.ToString().Trim();
sendStokerdprice = this.dataGridView1.Rows[intCurrentRowNumber].Cells[5].Value.ToString().Trim();
sendStokerke = this.dataGridView1.Rows[intCurrentRowNumber].Cells[3].Value.ToString().Trim();
sendStokerxishu = this.dataGridView1.Rows[intCurrentRowNumber].Cells[4].Value.ToString().Trim();
sendStokerlprice = this.dataGridView1.Rows[intCurrentRowNumber].Cells[6].Value.ToString().Trim();
string[] sendArray = new string[] { sendStokername, sendStokerdprice, sendStokerke, sendStokerxishu, sendStokerlprice };
calc.inputTextDataArray[0] = sendArray[0];
calc.inputTextDataArray[1] = sendArray[1];
calc.inputTextDataArray[2] = sendArray[2];
calc.inputTextDataArray[3] = sendArray[3];
calc.inputTextDataArray[4] = sendArray[4];
this.Close();
}
}
public void setDataGridReadOnly()
{
this.dataGridView1.ReadOnly = true;
}
form1窗体中的主要事件代码为:public void datalist()
{
string mysql = "select papertypes as 用纸类型,len as 长,wid as 宽,ke as 克重,xishu as 系数,dprice as 吨价,lprice as 令价 from system_paperprice";
DataSet grid = new DataSet();
string connectionString = ConfigurationManager.ConnectionStrings["进销存管理系统.Properties.Settings.ld_ysglConnectionString"].ConnectionString;
SqlConnection myConnection = new SqlConnection(connectionString);
myConnection.Open();
grid.Clear();
SqlDataAdapter myda = new SqlDataAdapter(mysql, myConnection);
myda.Fill(grid);
dataGridView1.DataSource = grid.Tables[0];
myConnection.Close();
}
//双击选择用纸类型信息并回送到调用的窗体-------------
private void dataGridView1_DoubleClick(object sender, System.EventArgs e)
{
if (this.dataGridView1.ReadOnly == true)
{
int intCurrentRowNumber = this.dataGridView1.CurrentCell.RowIndex;
string sendStokername, sendStokerdprice, sendStokerke, sendStokerxishu, sendStokerlprice;
sendStokername = this.dataGridView1.Rows[intCurrentRowNumber].Cells[0].Value.ToString().Trim();
sendStokerdprice = this.dataGridView1.Rows[intCurrentRowNumber].Cells[5].Value.ToString().Trim();
sendStokerke = this.dataGridView1.Rows[intCurrentRowNumber].Cells[3].Value.ToString().Trim();
sendStokerxishu = this.dataGridView1.Rows[intCurrentRowNumber].Cells[4].Value.ToString().Trim();
sendStokerlprice = this.dataGridView1.Rows[intCurrentRowNumber].Cells[6].Value.ToString().Trim();
string[] sendArray = new string[] { sendStokername, sendStokerdprice, sendStokerke, sendStokerxishu, sendStokerlprice };
calc.inputTextDataArray[0] = sendArray[0];
calc.inputTextDataArray[1] = sendArray[1];
calc.inputTextDataArray[2] = sendArray[2];
calc.inputTextDataArray[3] = sendArray[3];
calc.inputTextDataArray[4] = sendArray[4];
this.Close();
}
}
public void setDataGridReadOnly()
{
this.dataGridView1.ReadOnly = true;
}
public static string[] inputTextDataArray = new string[] { "", "", "", "", "" };
private LinkDataBase link = new LinkDataBase();
public calc()
{
InitializeComponent();
this.comboBox2.Items.Add("");
}
//-------将双击选择得到的用纸类型信息显示到窗体中--------
private void setTextData()
{
this.comboBox2.IntegralHeight = false;//使组合框不调整大小以显示其所有项
this.comboBox2.DroppedDown = false;//使组合框不显示其下拉部分
this.comboBox2.Items[0] = inputTextDataArray[0];
this.comboBox2.SelectedIndex = 0;
this.textBox20.Text = inputTextDataArray[1];
this.textBox18.Text = inputTextDataArray[2];
this.textBox10.Text = inputTextDataArray[3];
this.textBox2.Text = inputTextDataArray[4];
this.comboBox2.IntegralHeight = true;//恢复默认值
}
//----------创建窗体,供用户选择用纸类型----------
private void cmb_Stoker_DropDown(object sender, System.EventArgs e)
{
make newFrm = new make();
newFrm.setDataGridReadOnly();
newFrm.ShowDialog();
setTextData();
SendKeys.Send("{Tab}");//向活动应用程序发送Tab键,跳到下一控件
}
//--------将所选用纸信息的相关数据读入窗体---------
private void cmb_StokerID_KeyUp(object sender, System.Windows.Forms.KeyEventArgs e)
{
this.textBox20.Text = "";
this.textBox18.Text = "";
this.textBox10.Text = "";
this.textBox2.Text = "";
string strSearchWord = this.comboBox2.Text;
string sendSQL = "select papertypes,dprice,ke,xishu,lprice from system_paperprice where papertypes = '" + strSearchWord + "'";
DataTable tempDataTable = this.link.SelectDataBase(sendSQL);
if (tempDataTable.Rows.Count > 0)
{
inputTextDataArray[0] = tempDataTable.Rows[0][0].ToString().Trim();
inputTextDataArray[1] = tempDataTable.Rows[0][1].ToString().Trim();
inputTextDataArray[2] = tempDataTable.Rows[0][2].ToString().Trim();
inputTextDataArray[3] = tempDataTable.Rows[0][3].ToString().Trim();
inputTextDataArray[4] = tempDataTable.Rows[0][4].ToString().Trim();
this.setTextData();
SendKeys.Send("{Tab}");//向活动应用程序发送Tab键,跳到下一控件
}
}
private LinkDataBase link = new LinkDataBase();
public calc()
{
InitializeComponent();
this.comboBox2.Items.Add("");
}
//-------将双击选择得到的用纸类型信息显示到窗体中--------
private void setTextData()
{
this.comboBox2.IntegralHeight = false;//使组合框不调整大小以显示其所有项
this.comboBox2.DroppedDown = false;//使组合框不显示其下拉部分
this.comboBox2.Items[0] = inputTextDataArray[0];
this.comboBox2.SelectedIndex = 0;
this.textBox20.Text = inputTextDataArray[1];
this.textBox18.Text = inputTextDataArray[2];
this.textBox10.Text = inputTextDataArray[3];
this.textBox2.Text = inputTextDataArray[4];
this.comboBox2.IntegralHeight = true;//恢复默认值
}
//----------创建窗体,供用户选择用纸类型----------
private void cmb_Stoker_DropDown(object sender, System.EventArgs e)
{
make newFrm = new make();
newFrm.setDataGridReadOnly();
newFrm.ShowDialog();
setTextData();
SendKeys.Send("{Tab}");//向活动应用程序发送Tab键,跳到下一控件
}
//--------将所选用纸信息的相关数据读入窗体---------
private void cmb_StokerID_KeyUp(object sender, System.Windows.Forms.KeyEventArgs e)
{
this.textBox20.Text = "";
this.textBox18.Text = "";
this.textBox10.Text = "";
this.textBox2.Text = "";
string strSearchWord = this.comboBox2.Text;
string sendSQL = "select papertypes,dprice,ke,xishu,lprice from system_paperprice where papertypes = '" + strSearchWord + "'";
DataTable tempDataTable = this.link.SelectDataBase(sendSQL);
if (tempDataTable.Rows.Count > 0)
{
inputTextDataArray[0] = tempDataTable.Rows[0][0].ToString().Trim();
inputTextDataArray[1] = tempDataTable.Rows[0][1].ToString().Trim();
inputTextDataArray[2] = tempDataTable.Rows[0][2].ToString().Trim();
inputTextDataArray[3] = tempDataTable.Rows[0][3].ToString().Trim();
inputTextDataArray[4] = tempDataTable.Rows[0][4].ToString().Trim();
this.setTextData();
SendKeys.Send("{Tab}");//向活动应用程序发送Tab键,跳到下一控件
}
}
- 双击dataGridView后的数据传递示例
- 双击dataGridView一行数据,打开一个另一个窗体,并把双击行的数据展示出来
- C# WinForm 双击DataGridView修改数据
- 在两个不同的Form窗体中的DataGridView数据“传递”
- c#中dataGridView数据绑定后的数据操作
- DataGridView显示数据是,取消双击列标题触发的事件
- winforms的datagridview双击事件传值
- winform DataGridView双击修改单元格的值
- C# datagridview 从excel导入数据后时间的显示
- DataGridView窗体之间的传递
- DataGridView数据绑定以及导出Excel示例
- U6数据导出工具项目总结三 鼠标单击或者双击DataGridView控件时获取鼠标点击位置的值
- dataGridView的数据打印
- dataGridView的数据打印
- dataGridView的数据打印
- DataGridView数据的绑定
- datagridview 绑定后的操作
- datagridview 绑定数据后,更新update()问题
- EVC4.0+AdoCe3.1访问Access数据库全攻略(附带说明及例程)
- 达内CEO:中美开发三大不同,中国程序员更难做
- 关于PDU模式发送短信,千万可别被误导
- VS2005 专业教程 上一个 经典的源码
- C#示例 自动更新程序
- 双击dataGridView后的数据传递示例
- AJAX框架 jMaki (一) - 介绍及安装
- oracle的listener无法启动"错误3,系统找不到指定路径"
- Spring.Net&NHibernate 学习 5
- ASP.NET面试题
- 最新JMF包
- Scientists’ Good News: Earth May Survive Sun’s Demise in 5 Billion Years
- NET 下数据库图片的存入与读取
- 工作总结