很多軟件都能實現:
當用戶點一個Button彈出Form2,然後從Form2中的DataGrid中選中一條數據,關閉Form2,並在Form1中相關的多個textBox上顯示Form2中的數據....------------------------------
點Button--->彈出Form2或是自制控件----->選中裡面的一條數據,確定------->關閉Form2或是自制控件,並在form1中相對應的幾個TextBox中顯示剛才選中的數據====================請問如何實現===================================
當用戶點一個Button彈出Form2,然後從Form2中的DataGrid中選中一條數據,關閉Form2,並在Form1中相關的多個textBox上顯示Form2中的數據....------------------------------
點Button--->彈出Form2或是自制控件----->選中裡面的一條數據,確定------->關閉Form2或是自制控件,並在form1中相對應的幾個TextBox中顯示剛才選中的數據====================請問如何實現===================================
解决方案 »
- C# 多线程问题求救~~急!!
- 客户端运行水晶报表,出现登录窗口
- 编辑框里填入整数问题!
- 新手跪求 v c#连接数据库的方法!高分,在线等.
- 请教在(父页面)用 button弹出新的窗口页面(子页面)后,如何将子页面中的某个值传回给父页面的一个textbox.text!!急急
- XtraGrid 中如何实现 比如数据库是 M 则列显示男 数据库是F则显示女 这样的功能呢
- Winform 两个DataTable把相同数据合并,统计数量相加!
- 请教c#在sql更新日期问题
- 用javascrip为什么ie总报错 document.getElementById('Button1')不是对象?
- C#中在TabControl中加入WebBrowse控件为什么不能正确使用?
- C#开发ASP.net中控件隐藏的问题
- 关于windows service 的一个很久都没解决的问题,高手帮忙啊!!!
*****************************************************************************
欢迎使用CSDN论坛阅读器 : CSDN Reader(附全部源代码)
http://www.cnblogs.com/feiyun0112/archive/2006/09/20/509783.html
{
DataSet ds = form2.SelectedRow;
}在form2里定义一个属性,记录下被选中的行。
<script language="javascript">
function ChooseXX(){
window.open("xxxxx.aspx","","height=450,left=200,width=600,scrollbars=yes,location=no,menubar=no,titlebar=no,toolbar=no");
}
</script><asp:TextBox id="txtEmpName" runat="server" Width="136px" ReadOnly="True"></asp:TextBox>
<INPUT type="button" value="选择XX" onclick="ChooseXX()" class="CssButton4"><INPUT id="hiddenEmpID" type="hidden" runat="server" NAME="hiddenEmpID">
<asp:TextBox id="txtDepName" runat="server" Width="280px" ReadOnly="True"></asp:TextBox>
然后在Form2中是一个DATAGRID,在ItemDataBound事件中做:
if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
int empID = int.Parse(e.Item.Cells[0].Text);
string empName = e.Item.Cells[1].Text;
string empDepName = e.Item.Cells[5].Text;
e.Item.Attributes.Add("onclick","window.opener.document.getElementById('txtEmpName').innerText='" + empName + "';window.opener.document.getElementById('hiddenEmpID').value='" + empID + "';window.opener.document.getElementById('txtDepName').innerText='" + empDepName + "';window.close();");
}
把这个属性设为Form1
然后再Form2中操作这个属性就可以了你还可以在Form2 中定义委托
发出一个事件
在Form1中new Form2的时候
订阅这个事件
http://blog.csdn.net/zhzuo/archive/2004/04/05/22027.aspx
创建属性,修改构造函数,静态,委托都可以
我也搜到这个了
http://blog.csdn.net/zhzuo/archive/2004/04/05/22027.aspx
public bool passedbool;
然后修改Form2的构造函数:
Form parent = null;
public Form2(Form form)
{
InitializeComponent();
parent = form;
}
然后Form1调用Form2:
Form2 s = new TreeView(Form1.ActiveForm);
s.ShowDialog();
然后在Form2某个事件事调用Form1: private void button1_Click(object sender, EventArgs e)
{
Form1 s = parent as Form1;
s.passedbool = true;
}
运行,OK。
-----------------------------
using System;
using System.Data;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;namespace DrawForm
{
public delegate void ChangeData(DataTable senData);
/// <summary>
/// Summary description for Form2.
/// </summary>
public class Form2 : System.Windows.Forms.Form
{
public event ChangeData SelectedData;
private System.Windows.Forms.Button btnSelectData;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null; public Form2()
{
//
// Required for Windows Form Designer support
//
InitializeComponent(); //
// TODO: Add any constructor code after InitializeComponent call
//
} /// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
} #region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.btnSelectData = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// btnSelectData
//
this.btnSelectData.Location = new System.Drawing.Point(96, 72);
this.btnSelectData.Name = "btnSelectData";
this.btnSelectData.TabIndex = 3;
this.btnSelectData.Text = "button1";
this.btnSelectData.Click += new System.EventHandler(this.btnSelectData_Click);
//
// Form2
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 273);
this.Controls.Add(this.btnSelectData);
this.Name = "Form2";
this.Text = "Form2";
this.ResumeLayout(false); }
#endregion private void btnSelectData_Click(object sender, System.EventArgs e)
{
DataTable dt = new DataTable();
dt.Columns.Add("UserName");
dt.Columns.Add("Connect");
dt.Columns.Add("Phone");
for(int i = 0; i < 3; i++)
{
DataRow dr = dt.NewRow();
foreach(DataColumn dc in dt.Columns)
{
dr[dc.ColumnName] = i.ToString() + dc.ColumnName;
}
}
this.SelectedData(dt);
}
}
}Form1的关键代码
------------------------------------
private void Form1_Load(object sender, System.EventArgs e)
{
Form2 form = new Form2();
form.Owner = this;
form.SelectedData += new ChangeData(this.GetReturnData);
form.Show();
} private void GetReturnData(DataTable dt)
{
this.dataGrid1.DataSource = dt;
this.dataGrid1.DataMember = dt.TableName;
}