在表单类之间传递参数 - C# [英] Passing Parameters between form classes - C#

查看:69
本文介绍了在表单类之间传递参数 - C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是C#和OO的新手所以请不要笑!我有一个表格

(fclsTaxCalculator),其中包含一个包含zip

代码的文本框(tboxZipCode)。用户可以在文本框中输入邮政编码,然后单击按钮以确定邮政编码是否唯一。如果邮政编码不是唯一的,则显示另一个表单/对话框(fclsLookup) - 查找表单/对话框。
zip

代码和zipid都通过引用传递给查找表单/对话框。我

然后加载一个带有可能匹配的数据网格(即zip,city,county,

state,zipid)。

当用户点击时在datagrid中的行,我想将zipid传回

到原始表单/对话框并运行存储过程。我的问题是我做了什么

不知道如何将ZipId恢复到fclsTaxCalculator表单/对话框。

我还没弄明白如何设置变量通过了

mousedown活动。我已经找到了这方面的例子,而且我无法跟踪
跟踪一个 -

请帮忙!我的代码如下所示:


//这是fclsTaxCalculator类中传递ref

变量的事件

private void lblZipCode_Click(object sender,System.EventArgs e)

{

strZipCode = tboxZip.Text;

fclsLookup objLookupForm = new fclsLookup(ref strZipCode ,ref

strZipCodeDtlId);

objLookupForm.Show();

tboxZip.Text = strZipCode;

}


//这是接收ref变量的fclsLookup,我无法想象

如何

/ /将变量设置为所选值。


使用System;

使用System.Drawing;

使用System.Collections;

使用System.ComponentModel;

使用System.Windows.Forms;

使用System.Data;

使用System.Data.SqlClient;


名称空间EnspireUtilities

{

///< summary>

///的摘要说明查询。

///< / summary>

公共类fclsLookup:System.Windows.Forms.Form

{

private System.Data.SqlClient.SqlDataAdapter sqlDataAdapter1;

private System.Data.SqlClient.SqlCommand sqlSelectCommand1;

private System.Data.SqlClient.SqlConnection sqlConnection1;

private EnspireUtilities.dsLookup dsLookup1;

private System.Windows.Forms.DataGrid dataGrid1;

private System.Windows.Forms.Button btnLoad;

private System.Windows.Forms.TextBox tboxLookupZipCode;

private System.Windows.Forms.Label lblLookupParameter;

private System.Windows.Forms .Button btnOK;

private System.Windows.Forms.Button btnCancel;

// private string strZipCode = string.Empty;

private System .Windows.Forms.DataGridTableStyle dataGridTableStyle1;

private System.Windows.Forms.DataGridTextBoxColumn dataGridTextBoxColumn1;

private System.Windo ws.Forms.DataGridTextBoxColumn dataGridTextBoxColumn2;

private System.Windows.Forms.DataGridTextBoxColumn dataGridTextBoxColumn3;

private System.Windows.Forms.DataGridTextBoxColumn dataGridTextBoxColumn4;

public string strZipCode = String.Empty;

public string strZipCodeDtlId = String.Empty;

///< summary>

// /必需的设计变量。

///< / summary>

private System.ComponentModel.Container components = null;


public fclsLookup(ref string ZipCode,ref string ZipCodeDtlId)

{

//

// Windows Form Designer支持需要

//

InitializeComponent();


//

// TODO:之后添加任何构造函数代码InitializeComponent调用

//

//tboxLookupZipCode.Text = ZipCode;

sqlSelectCommand1.Parameters [" @ zip"]。Value = ZipCode ;

dsLookup1.Clear();

s qlDataAdapter1.Fill(dsLookup1);

strZipCode = ZipCode;

strZipCodeDtlId = ZipCodeDtlId;

tboxLookupZipCode.Text = strZipCode;

this.dataGrid1.MouseDown + = new

System.Windows.Forms.MouseEventHandler(this.dataGr id1_MouseDown);

}


///< summary>

///清理正在使用的所有资源。

///< / summary>

protected override void Dispose(bool disposing)

{

if(disposing)

{

if (组件!= null)

{

components.Dispose();

}

}

base.Dispose(disposing);

}


#region Windows窗体设计器生成的代码

// /< summary>

/// Designer支持所需的方法 - 不要使用代码编辑器修改

///此方法的内容。

///< / summary>

private void InitializeComponent()

{

this.sqlDataAdapter1 = new System.Data.SqlClient.SqlDataAdapter();

this.sqlSelectCommand1 = new System.Data.SqlClient.SqlCommand();

this.sqlConnection1 = new System.Data.SqlClient.SqlConnection();

this.dsLookup1 = new EnspireUtilities.dsLookup();

this.dataGrid1 = new System.Windows.Forms.DataGrid();

this.dataGridTableStyle1 = new System.Windows.Forms.DataGridTableStyle();

this.dataGridTextBoxColumn1 = new

System.Windows.Forms.DataGridTextBoxColumn();

this.dataGridTextBoxColumn2 = new

System.Windows.Forms.DataGridTextBoxColumn();

this.dataGridTextBoxColumn3 = new

System.Windows.Forms.DataGridTextBoxColumn();

this.dataGridTextBoxColumn4 = new

System.Windows .Forms.DataGridTextBoxColumn();

this.btnLoad = new System.Windows.Forms.Button();

this.tboxLookupZipCode = new System.Windows.Forms.TextBox ();

this.lb lLookupParameter = new System.Windows.Forms.Label();

this.btnOK = new System.Windows.Forms.Button();

this.btnCancel = new System .Windows.Forms.Button();

((System.ComponentModel.ISupportInitialize)(this.d sLookup1))。BeginInit();

((System.ComponentModel .ISupportInitialize)(this.d ataGrid1))。BeginInit();

this.SuspendLayout();

//

// sqlDataAdapter1

//

this.sqlDataAdapter1.SelectCommand = this.sqlSelectCommand1;

this.sqlDataAdapter1.TableMappings.AddRange(new

System.Data.Common.DataTableMapping [] {

new System.Data.Common.DataTableMapping(" Table",

" p_getZipCodeData",new System .Data.Common.DataColumnMapping [] {

new

System.Data.Common.DataColumnMapping(" zip"," zip"),

new

System.Data.Common.DataColumnMapping(" city"," city"),

new

System.Data.Common.DataColumnMapping(" county"," county"),

new

System.Data.Common.DataColumnMapping(" state", state),

new

System.Data.Common.DataColumnMapping(" zip_code_dtl _id",

" zip_code_dtl_id") });

//

// sqlSelectCommand1

//

this.sqlSelectCommand1.CommandText = " [p_getZipCodeData]";

this.sqlSelectCommand1.CommandType =

System.Data.CommandType.StoredProcedure;

this.sqlSelectCommand1。 Connection = this.sqlConnection1;

this.sqlSelectCommand1.Parameters.Add(new

System.Data.SqlClient.SqlParameter(" @ RETURN_VALUE" ,

System.Data.SqlDbType.Int,4,System.Data.ParameterDirection.ReturnValue,

false,((System.Byte)(0)),(( System.Byte)(0)),",

System.Data.DataRowVersion.Current,null));

this.sqlSelectCommand1.Parameters.Add( new

System.Data.SqlClient.SqlParameter(" @ zip",System.Data.SqlDbType.VarChar,

10));

//

// sqlConnection1

//

this.sqlConnection1.ConnectionString =" workstation id = CENGENXP2; packet

size = 4096; user id = sa; data source = cengenxp2; persis" +

" t security info = True;初始目录= src;密码= cocacola" ;;

//

// dsLookup1

//

this.dsLookup1.DataSetName =" dsLookup";

this.dsLookup1.Locale = new System.Globalization.CultureInfo(" en-US);

//

// dataGrid1

//

this.dataGrid1.DataMember =" p_getZipCodeData";

this.dataGrid1.DataSource = this.dsLookup1;

this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText;

this.dataGrid1.Location = new System.Drawing.Point(0,40);

this.dataGrid1.Name =" dataGrid1";

this .dataGrid1.Size = new System.Drawing.Size(568,288);

this.dataGrid1.TabIndex = 0;

this.dataGrid1.TableStyles.AddRange(new

System.Windows.Forms.DataGridTableStyle [] {

this.dataGridTableStyle1});

this.dataGrid1.Navigate + = new

System.Windows.F orms.NavigateEventHandler(this.dat aGrid1_Navigate);

//

// dataGridTableStyle1

//

this .dataGridTableStyle1.DataGrid = this.dataGrid1;

this.dataGridTableStyle1.GridColumnStyles.AddRange(new

System.Windows.Forms.DataGridColumnStyle [] {

this.dataGridTextBoxColumn1,

this.dataGridTextBoxColumn2,

this.dataGridTextBoxColumn3,

this.dataGridTextBoxColumn4});

this.dataGridTableStyle1.HeaderForeColor =

System.Drawing.SystemColors.ControlText;

this.dataGridTableStyle1.MappingName =" p_getZipCodeData";

//

// dataGridTextBoxColumn1

//

this.dataGridTextBoxColumn1.Format ="" ;;

this.dataGridTextBoxColumn1.FormatInfo = null;

this.dataGridTextBoxColumn1.HeaderText =" Zip Code";

this.dataGridTextBoxColumn1.MappingName =" zip";

this.data GridTextBoxColumn1.Width = 75;

//

// dataGridTextBoxColumn2

//

this.dataGridTextBoxColumn2.Format ="" ;;

this.dataGridTextBoxColumn2.FormatInfo = null;

this.dataGridTextBoxColumn2.HeaderText =" City";

this .dataGridTextBoxColumn2.MappingName =" city";

this.dataGridTextBoxColumn2.Width = 75;

//

// dataGridTextBoxColumn3
//

this.dataGridTextBoxColumn3.Format ="" ;;

this.dataGridTextBoxColumn3.FormatInfo = null;

this.dataGridTextBoxColumn3.HeaderText =" County";

this.dataGridTextBoxColumn3.MappingName =" county";

this.dataGridTextBoxColumn3.Width = 75;

//

// dataGridTextBoxColumn4

//

this.dataGridTextBoxColumn4.Format ="" ;;

this.dataGridTextBoxColumn4.FormatInfo = null;

this.dataGridTe xtBoxColumn4.HeaderText =" State";

this.dataGridTextBoxColumn4.MappingName =" state";

this.dataGridTextBoxColumn4.Width = 75;

//

// btnLoad

//

this.btnLoad.Location = new System.Drawing.Point(472,8) ;

this.btnLoad.Name =" btnLoad";

this.btnLoad.TabIndex = 2;

this.btnLoad.Text = 加载;

this.btnLoad.C​​lick + = new System.EventHandler(this.btnLoad_Click);

//

// tboxLookupZipCode

//

this.tboxLookupZipCode.Location = new System.Drawing.Point(136,8);

this.tboxLookupZipCode.Name =" tboxLookupZipCode";

this.tboxLookupZipCode.Size = new System.Drawing.Size(200,20);

this.tboxLookupZipCode.TabIndex = 1;

this.tboxLookupZipCode.Text ="" ;;

//

// lblLookupParameter

//

this.lblLookupParameter.Location = new System.Drawing.Point(24,8);

this.lblLookupParameter.Name =" lblLookupParameter" ;;

this.lblLookupParameter.Size = new System.Drawing。大小(100,20);

this.lblLookupParameter.TabIndex = 3;

this.lblLookupParameter.Text =" Zip Code";

this.lblLookupParameter.TextAlign =

System.Drawing.ContentAlignment.MiddleRight;

//

// btnOK

//

this.btnOK.DialogResult = System.Windows.Forms.DialogResult.OK;

this.btnOK.Location = new System.Drawing.Point(378 ,352);

this.btnOK.Name =" btnOK";

this.btnOK.TabIndex = 3;

this.btnOK .Text =" OK";

this.btnOK.Click + = new System.EventHandler(this.btnOK_Click);

//

// btnCancel

//

this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;

this.btnCancel。 Location = new System.Drawing.Point(472,352) ;

this.btnCancel.Name =" btnCancel";

this.btnCancel.TabIndex = 4;

this.btnCancel.Text = 取消;

this.btnCancel.Click + = new System.EventHandler(this.btnCancel_Click);

//

// fclsLookup

//

this.AutoScaleBaseSize = new System.Drawing.Size(5,13);

this.ClientSize = new System。 Drawing.Size(568,390);

this.Controls.Add(this.btnCancel);

this.Controls.Add(this.btnOK);

this.Controls.Add(this.lblLookupParameter);

this.Controls.Add(this.tboxLookupZipCode);

this.Controls.Add(this .btnLoad);

this.Controls.Add(this.dataGrid1);

this.Name =" fclsLookup";

this。 Text =" Lookup";

((System.ComponentModel.ISupportInitialize)(this.d sLookup1))。EndInit();

((System.ComponentModel.ISupportInitialize )(this.d ataGrid1))。EndInit();

this.ResumeLayout(false) ;


}

#endregion

private void btnLoad_Click(object sender,System.EventArgs e)

{

sqlSelectCommand1.Parameters [" @ zip"]。Value = tboxLookupZipCode.Text;

dsLookup1.Clear();

sqlDataAdapter1.Fill(dsLookup1);

}


private void btnOK_Click(object sender,System.EventArgs e)

{


关闭();

}


private void btnCancel_Click(object sender,System.EventArgs e)

{

关闭();

}


private void dataGrid1_Navigate(object sender,

System.Windows.Forms.NavigateEventArgs ne)

{


关闭();

}


protected void dataGrid1_MouseDown(object sender,

System.Windows.Forms.MouseEventArgs e)

{

string strMessage =" TEST";


// strMessage =" Row:" + dataGrid1.HitTest(eX,eY).Row.ToString();

int x = dataGrid1.HitTest(eX,eY).Row;


strZipCode = dataGrid1 [x,0] .ToString();

strZipCodeDtlId = dataGrid1 [x,3] .ToString();

ZipCodeDtlId = strZipCodeDtlId;

MessageBox.Show(strZipCode);

MessageBox.Show(我仍然不知道我在做什么,但我在'+

strMessage +"。我需要发回+ strZipCode;

}


}

}

I''m a rookie at C# and OO so please don''t laugh! I have a form
(fclsTaxCalculator) that contains a text box (tboxZipCode) containing a zip
code. The user can enter a zip code in the text box and click a button to
determine whether the zip code is unique. If the zip code is not unique,
another form/dialog is displayed (fclsLookup) - lookup form/dialog. The zip
code and zipid are both passed to the lookup form/dialog by reference. I
then load a datagrid with the possible matches (i.e. zip, city, county,
state, zipid).
When the user clicks the row in the datagrid, I want to pass the zipid back
to the original form/dialog and run a stored procedure. My problem is I do
not know how to get the ZipId back to the fclsTaxCalculator form/dialog.
I''ve not figured out how to set the variable that was passed in the
mousedown event. I''ve search for examples of this and I''ve not been able to
track one down -
please help!!! My code is shown below:

//this is the event in the fclsTaxCalculator class that passes the ref
variables
private void lblZipCode_Click(object sender, System.EventArgs e)
{
strZipCode = tboxZip.Text;
fclsLookup objLookupForm = new fclsLookup(ref strZipCode, ref
strZipCodeDtlId);
objLookupForm.Show();
tboxZip.Text = strZipCode;
}

//this is the fclsLookup that receives the ref variable and I can''t figure
out how to
//set the variables to the selected value.

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;

namespace EnspireUtilities
{
/// <summary>
/// Summary description for Lookup.
/// </summary>
public class fclsLookup : System.Windows.Forms.Form
{
private System.Data.SqlClient.SqlDataAdapter sqlDataAdapter1;
private System.Data.SqlClient.SqlCommand sqlSelectCommand1;
private System.Data.SqlClient.SqlConnection sqlConnection1;
private EnspireUtilities.dsLookup dsLookup1;
private System.Windows.Forms.DataGrid dataGrid1;
private System.Windows.Forms.Button btnLoad;
private System.Windows.Forms.TextBox tboxLookupZipCode;
private System.Windows.Forms.Label lblLookupParameter;
private System.Windows.Forms.Button btnOK;
private System.Windows.Forms.Button btnCancel;
//private string strZipCode = string.Empty;
private System.Windows.Forms.DataGridTableStyle dataGridTableStyle1;
private System.Windows.Forms.DataGridTextBoxColumn dataGridTextBoxColumn1;
private System.Windows.Forms.DataGridTextBoxColumn dataGridTextBoxColumn2;
private System.Windows.Forms.DataGridTextBoxColumn dataGridTextBoxColumn3;
private System.Windows.Forms.DataGridTextBoxColumn dataGridTextBoxColumn4;
public string strZipCode = String.Empty;
public string strZipCodeDtlId = String.Empty;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;

public fclsLookup(ref string ZipCode, ref string ZipCodeDtlId)
{
//
// Required for Windows Form Designer support
//
InitializeComponent();

//
// TODO: Add any constructor code after InitializeComponent call
//
//tboxLookupZipCode.Text = ZipCode;
sqlSelectCommand1.Parameters["@zip"].Value = ZipCode;
dsLookup1.Clear();
sqlDataAdapter1.Fill(dsLookup1);
strZipCode = ZipCode;
strZipCodeDtlId = ZipCodeDtlId;
tboxLookupZipCode.Text = strZipCode;
this.dataGrid1.MouseDown += new
System.Windows.Forms.MouseEventHandler(this.dataGr id1_MouseDown);
}

/// <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.sqlDataAdapter1 = new System.Data.SqlClient.SqlDataAdapter();
this.sqlSelectCommand1 = new System.Data.SqlClient.SqlCommand();
this.sqlConnection1 = new System.Data.SqlClient.SqlConnection();
this.dsLookup1 = new EnspireUtilities.dsLookup();
this.dataGrid1 = new System.Windows.Forms.DataGrid();
this.dataGridTableStyle1 = new System.Windows.Forms.DataGridTableStyle();
this.dataGridTextBoxColumn1 = new
System.Windows.Forms.DataGridTextBoxColumn();
this.dataGridTextBoxColumn2 = new
System.Windows.Forms.DataGridTextBoxColumn();
this.dataGridTextBoxColumn3 = new
System.Windows.Forms.DataGridTextBoxColumn();
this.dataGridTextBoxColumn4 = new
System.Windows.Forms.DataGridTextBoxColumn();
this.btnLoad = new System.Windows.Forms.Button();
this.tboxLookupZipCode = new System.Windows.Forms.TextBox();
this.lblLookupParameter = new System.Windows.Forms.Label();
this.btnOK = new System.Windows.Forms.Button();
this.btnCancel = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.d sLookup1)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.d ataGrid1)).BeginInit();
this.SuspendLayout();
//
// sqlDataAdapter1
//
this.sqlDataAdapter1.SelectCommand = this.sqlSelectCommand1;
this.sqlDataAdapter1.TableMappings.AddRange(new
System.Data.Common.DataTableMapping[] {
new System.Data.Common.DataTableMapping("Table",
"p_getZipCodeData", new System.Data.Common.DataColumnMapping[] {
new
System.Data.Common.DataColumnMapping("zip", "zip"),
new
System.Data.Common.DataColumnMapping("city", "city"),
new
System.Data.Common.DataColumnMapping("county", "county"),
new
System.Data.Common.DataColumnMapping("state", "state"),
new
System.Data.Common.DataColumnMapping("zip_code_dtl _id",
"zip_code_dtl_id")})});
//
// sqlSelectCommand1
//
this.sqlSelectCommand1.CommandText = "[p_getZipCodeData]";
this.sqlSelectCommand1.CommandType =
System.Data.CommandType.StoredProcedure;
this.sqlSelectCommand1.Connection = this.sqlConnection1;
this.sqlSelectCommand1.Parameters.Add(new
System.Data.SqlClient.SqlParameter("@RETURN_VALUE" ,
System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.ReturnValue,
false, ((System.Byte)(0)), ((System.Byte)(0)), "",
System.Data.DataRowVersion.Current, null));
this.sqlSelectCommand1.Parameters.Add(new
System.Data.SqlClient.SqlParameter("@zip", System.Data.SqlDbType.VarChar,
10));
//
// sqlConnection1
//
this.sqlConnection1.ConnectionString = "workstation id=CENGENXP2;packet
size=4096;user id=sa;data source=cengenxp2;persis" +
"t security info=True;initial catalog=src;password=cocacola";
//
// dsLookup1
//
this.dsLookup1.DataSetName = "dsLookup";
this.dsLookup1.Locale = new System.Globalization.CultureInfo("en-US");
//
// dataGrid1
//
this.dataGrid1.DataMember = "p_getZipCodeData";
this.dataGrid1.DataSource = this.dsLookup1;
this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
this.dataGrid1.Location = new System.Drawing.Point(0, 40);
this.dataGrid1.Name = "dataGrid1";
this.dataGrid1.Size = new System.Drawing.Size(568, 288);
this.dataGrid1.TabIndex = 0;
this.dataGrid1.TableStyles.AddRange(new
System.Windows.Forms.DataGridTableStyle[] {
this.dataGridTableStyle1});
this.dataGrid1.Navigate += new
System.Windows.Forms.NavigateEventHandler(this.dat aGrid1_Navigate);
//
// dataGridTableStyle1
//
this.dataGridTableStyle1.DataGrid = this.dataGrid1;
this.dataGridTableStyle1.GridColumnStyles.AddRange (new
System.Windows.Forms.DataGridColumnStyle[] {
this.dataGridTextBoxColumn1,
this.dataGridTextBoxColumn2,
this.dataGridTextBoxColumn3,
this.dataGridTextBoxColumn4});
this.dataGridTableStyle1.HeaderForeColor =
System.Drawing.SystemColors.ControlText;
this.dataGridTableStyle1.MappingName = "p_getZipCodeData";
//
// dataGridTextBoxColumn1
//
this.dataGridTextBoxColumn1.Format = "";
this.dataGridTextBoxColumn1.FormatInfo = null;
this.dataGridTextBoxColumn1.HeaderText = "Zip Code";
this.dataGridTextBoxColumn1.MappingName = "zip";
this.dataGridTextBoxColumn1.Width = 75;
//
// dataGridTextBoxColumn2
//
this.dataGridTextBoxColumn2.Format = "";
this.dataGridTextBoxColumn2.FormatInfo = null;
this.dataGridTextBoxColumn2.HeaderText = "City";
this.dataGridTextBoxColumn2.MappingName = "city";
this.dataGridTextBoxColumn2.Width = 75;
//
// dataGridTextBoxColumn3
//
this.dataGridTextBoxColumn3.Format = "";
this.dataGridTextBoxColumn3.FormatInfo = null;
this.dataGridTextBoxColumn3.HeaderText = "County";
this.dataGridTextBoxColumn3.MappingName = "county";
this.dataGridTextBoxColumn3.Width = 75;
//
// dataGridTextBoxColumn4
//
this.dataGridTextBoxColumn4.Format = "";
this.dataGridTextBoxColumn4.FormatInfo = null;
this.dataGridTextBoxColumn4.HeaderText = "State";
this.dataGridTextBoxColumn4.MappingName = "state";
this.dataGridTextBoxColumn4.Width = 75;
//
// btnLoad
//
this.btnLoad.Location = new System.Drawing.Point(472, 8);
this.btnLoad.Name = "btnLoad";
this.btnLoad.TabIndex = 2;
this.btnLoad.Text = "Load";
this.btnLoad.Click += new System.EventHandler(this.btnLoad_Click);
//
// tboxLookupZipCode
//
this.tboxLookupZipCode.Location = new System.Drawing.Point(136, 8);
this.tboxLookupZipCode.Name = "tboxLookupZipCode";
this.tboxLookupZipCode.Size = new System.Drawing.Size(200, 20);
this.tboxLookupZipCode.TabIndex = 1;
this.tboxLookupZipCode.Text = "";
//
// lblLookupParameter
//
this.lblLookupParameter.Location = new System.Drawing.Point(24, 8);
this.lblLookupParameter.Name = "lblLookupParameter";
this.lblLookupParameter.Size = new System.Drawing.Size(100, 20);
this.lblLookupParameter.TabIndex = 3;
this.lblLookupParameter.Text = "Zip Code";
this.lblLookupParameter.TextAlign =
System.Drawing.ContentAlignment.MiddleRight;
//
// btnOK
//
this.btnOK.DialogResult = System.Windows.Forms.DialogResult.OK;
this.btnOK.Location = new System.Drawing.Point(378, 352);
this.btnOK.Name = "btnOK";
this.btnOK.TabIndex = 3;
this.btnOK.Text = "OK";
this.btnOK.Click += new System.EventHandler(this.btnOK_Click);
//
// btnCancel
//
this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.btnCancel.Location = new System.Drawing.Point(472, 352);
this.btnCancel.Name = "btnCancel";
this.btnCancel.TabIndex = 4;
this.btnCancel.Text = "Cancel";
this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click);
//
// fclsLookup
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(568, 390);
this.Controls.Add(this.btnCancel);
this.Controls.Add(this.btnOK);
this.Controls.Add(this.lblLookupParameter);
this.Controls.Add(this.tboxLookupZipCode);
this.Controls.Add(this.btnLoad);
this.Controls.Add(this.dataGrid1);
this.Name = "fclsLookup";
this.Text = "Lookup";
((System.ComponentModel.ISupportInitialize)(this.d sLookup1)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.d ataGrid1)).EndInit();
this.ResumeLayout(false);

}
#endregion
private void btnLoad_Click(object sender, System.EventArgs e)
{
sqlSelectCommand1.Parameters["@zip"].Value = tboxLookupZipCode.Text;
dsLookup1.Clear();
sqlDataAdapter1.Fill(dsLookup1);
}

private void btnOK_Click(object sender, System.EventArgs e)
{

Close();
}

private void btnCancel_Click(object sender, System.EventArgs e)
{
Close();
}

private void dataGrid1_Navigate(object sender,
System.Windows.Forms.NavigateEventArgs ne)
{

Close();
}

protected void dataGrid1_MouseDown(object sender,
System.Windows.Forms.MouseEventArgs e)
{
string strMessage = "TEST";

//strMessage = "Row: " + dataGrid1.HitTest(e.X,e.Y).Row.ToString();
int x = dataGrid1.HitTest(e.X, e.Y).Row;

strZipCode = dataGrid1[x, 0].ToString();
strZipCodeDtlId = dataGrid1[x, 3].ToString();
ZipCodeDtlId = strZipCodeDtlId;
MessageBox.Show(strZipCode);
MessageBox.Show("I still don''t know what I''m doing, but I''m at " +
strMessage + ". I need to send back " + strZipCode);
}

}
}

推荐答案

嗯...

MyClass

LookupDone (对象发送者,对象myArgs);


fclsLookup objLookupForm = new fclsLookup(MyClass this,strZipCode,

strZipCodeDtlId)

。 ..


FCLSLookup

...

myClass.LookupDone(this,myArgs);


//不可变的只读结构或类

struct myArgs {

私人邮编;

public string Zip {

get {return this.zip;}

}

}

问候,

Jeff


***通过Developersdex发送 http://www.developersdex.com ***

不要只参加USENET ......获得奖励!
Hmm...
MyClass
LookupDone(object sender, object myArgs);

fclsLookup objLookupForm = new fclsLookup(MyClass this, strZipCode,
strZipCodeDtlId)
...

FCLSLookup
...
myClass.LookupDone(this,myArgs);

// immutable readonly structure or class
struct myArgs {
private zip;
public string Zip {
get {return this.zip;}
}
}
Regards,
Jeff

*** Sent via Developersdex http://www.developersdex.com ***
Don''t just participate in USENET...get rewarded for it!


HI

你有两种传递方法

1.在你要打开的对话框中创建公共变量并传递zip

显示它之前对话框的代码

2.你可以在新的对话框中传递该变量。

Dialog dlg = new Dialog();

dlg.zip = zip.text;

dlg.show;

" Johnny" <乔**** @ discussions.microsoft.com>在消息中写道

news:46 ********************************** @ microsof t.com ...
HI
you have two methods to pass
1. create public variable in the dialog which you want to open and pass zip
code to dialog before show it
2. you can pass that variable while you generate your dialog in new.
Dialog dlg=new Dialog();
dlg.zip=zip.text;
dlg.show;
"Johnny" <Jo****@discussions.microsoft.com> wrote in message
news:46**********************************@microsof t.com...
我是C#和OO的新秀,所以请不要笑!我有一个表格
(fclsTaxCalculator),其中包含一个包含
zip
代码的文本框(tboxZipCode)。用户可以在文本框中输入邮政编码,然后单击按钮以确定邮政编码是否唯一。如果邮政编码不是唯一的,则显示另一个表格/对话框(fclsLookup) - 查找表格/对话框。
zip
代码和zipid都通过引用传递给查找表单/对话框。我然后加载一个带有可能匹配的数据网格(即zip,city,county,
state,zipid)。
当用户点击datagrid中的行时,我想传递zipid
返回原始表单/对话框并运行存储过程。我的问题是我不知道如何将ZipId恢复到fclsTaxCalculator表单/对话框。
我还没弄清楚如何设置在<传递的变量br /> mousedown事件。我已经找到了这方面的例子,但我还没有能够跟踪一个 -
请帮助!我的代码如下所示:

//这是fclsTaxCalculator类中传递ref
变量的事件
private void lblZipCode_Click(object sender,System.EventArgs e)
{
strZipCode = tboxZip.Text;
fclsLookup objLookupForm = new fclsLookup(ref strZipCode,ref
strZipCodeDtlId);
objLookupForm.Show();
tboxZip .Text = strZipCode;
}
//这是接收ref变量的fclsLookup,我不知道如何设置
//设置变量到选定的值。

使用System;
使用System.Drawing;
使用System.Collections;
使用System.ComponentModel;
使用System.Windows.Forms;
使用System.Data;
使用System.Data.SqlClient;

名称空间EnspireUtilities
{
///<摘要>
/// Lookup的摘要说明。
///< / summary>
公共类fclsLookup:System.Windows.Forms.Form
{
私人系统m.Data.SqlClient.SqlDataAdapter sqlDataAdapter1;
private System.Data.SqlClient.SqlCommand sqlSelectCommand1;
private System.Data.SqlClient.SqlConnection sqlConnection1;
private EnspireUtilities.dsLookup dsLookup1;
private System.Windows.Forms.DataGrid dataGrid1;
private System.Windows.Forms.Button btnLoad;
private System.Windows.Forms.TextBox tboxLookupZipCode;
private System.Windows.Forms。标签lblLookupParameter;
私有System.Windows.Forms.Button btnOK;
私有System.Windows.Forms.Button btnCancel;
//私有字符串strZipCode = string.Empty;
私有System.Windows.Forms.DataGridTableStyle dataGridTableStyle1;
private System.Windows.Forms.DataGridTextBoxColumn dataGridTextBoxColumn1;
private System.Windows.Forms.DataGridTextBoxColumn dataGridTextBoxColumn2;
private System.Windows.Forms.DataGridTextBoxColumn dataGridTextBoxColumn3 ;私有System.Windows.Forms.DataGridTextBoxColumn dataGridText BoxColumn4;
公共字符串strZipCode = String.Empty;
公共字符串strZipCodeDtlId = String.Empty;

///< summary>
///所需设计师变量。
///< / summary>
私有System.ComponentModel.Container components = null;
公共fclsLookup(ref string ZipCode,ref string ZipCodeDtlId)
{
//
// Windows窗体设计器支持需要
//
InitializeComponent();

//
// TODO:在InitializeComponent调用后添加任何构造函数代码//
//tboxLookupZipCode.Text = ZipCode;
sqlSelectCommand1.Parameters [" @ zip"]。Value = ZipCode;
dsLookup1.Clear();
sqlDataAdapter1.Fill(dsLookup1);
strZipCode = ZipCode;
strZipCodeDtlId = ZipCodeDtlId;
tboxLookupZipCode.Text = strZipCode;
this.dataGrid1 .MouseDown + = new
System.Windows.Forms.MouseEventHandler(this.dataGr id1_MouseDown);

}

///< summary>
/ //清理正在使用的所有资源。
///< / summary>
protected override void Dispose(bool disposing)
{
if(disposing)
{
if(components!= null)
{
components.Dispose();
}
}
base.Dispose(disposing);
}

#region Windows窗体设计器生成的代码
///< summary>
///设计器支持所需的方法 - 不要修改
/ //使用代码编辑器的方法的内容。
///< / summary>
private void InitializeComponent()
{
this.sqlDataAdapter1 = new System.Data .SqlClient.SqlDataAdapter();
this.sqlSelectCommand1 = new System.Data.SqlClient.SqlCommand();
this.sqlConnection1 = new System.Data.SqlClient.SqlConnection();
this .dsLookup1 = new EnspireUtilities.dsLookup();
this.dataGrid1 = new System.Windows.Forms.DataGrid();
this.dataGridTableStyle1 = new System.Windows.Forms.DataGridTableStyle();
this.dataGridTextBox Column1 = new
System.Windows.Forms.DataGridTextBoxColumn();
this.dataGridTextBoxColumn2 = new
System.Windows.Forms.DataGridTextBoxColumn();
this.dataGridTextBoxColumn3 = new <系统.Windows.Forms.DataGridTextBoxColumn();
this.dataGridTextBoxColumn4 = new
System.Windows.Forms.DataGridTextBoxColumn();
this.btnLoad = new System.Windows.Forms .Button();
this.tboxLookupZipCode = new System.Windows.Forms.TextBox();
this.lblLookupParameter = new System.Windows.Forms.Label();
this.btnOK = new System.Windows.Forms.Button();
this.btnCancel = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.d sLookup1)) .BeginInit();
((System.ComponentModel.ISupportInitialize)(this.d ataGrid1))。BeginInit();
this.SuspendLayout();
//
/ / sqlDataAdapter1
//
this.sqlDataAdapter1.SelectCommand = this.sqlSelectCommand1;
this.sqlDataAdapter1.TableMappings.AddRange(new System.Data.Common.DataTableMapping [] {
新的System.Data.Common.DataTableMapping(" Table",
" p_getZipCodeData",new System.Data.Common.DataColumnMapping [] {
新的
System.Data.Common.DataColumnMapping(" zip"," zip"),
new
System.Data.Common.DataColumnMapping(" city" ,city),
新的
System.Data.Common.DataColumnMapping(county,county),
新的System.Data.Common。 DataColumnMapping(state,state),
新的System.Data.Common.DataColumnMapping(" zip_code_dtl _id",
" zip_code_dtl_id")})});
//
// sqlSelectCommand1
//.sseSeqlCommand1.CommandText =" [p_getZipCodeData]" ;;
this.sqlSelectCommand1.CommandType =
System.Data.CommandType.StoredProcedure;
this.sqlSelectCommand1.Connection = this.sqlConnection1;
this.sqlSelectCommand1.Paramet ers.Add(new
System.Data.SqlClient.SqlParameter(" @ RETURN_VALUE" ,
System.Data.SqlDbType.Int,4,System.Data.ParameterDirection.ReturnValue,
false,((System.Byte)(0)),((System.Byte)(0)) ,",
System.Data.DataRowVersion.Current,null));
this.sqlSelectCommand1.Parameters.Add(new
System.Data.SqlClient.SqlParameter(" @) zip",System.Data.SqlDbType.VarChar,
10));
//
// sqlConnection1
// this.sqlConnection1.ConnectionString =" workstation id = CENGENXP2; packet
size = 4096; user id = sa; data source = cengenxp2; persis +
" t security info = True;初始目录= src;密码= cocacola" ;;
//
// dsLookup1
//
this.dsLookup1。 DataSetName =" dsLookup";
this.dsLookup1.Locale = new System.Globalization.CultureInfo(" en-US");
//
// dataGrid1
/ /
this.dataGrid1.DataMember =" p_getZipCodeData";
this.dataGrid1.DataSource = this.dsLookup1;
this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
this.dataGrid1.Location = new System.Drawing.Point(0,40);
this.dataGrid1.Name =" dataGrid1";
this.dataGrid1.Size = new System.Drawing。大小(568,288);
this.dataGrid1.TabIndex = 0;
this.dataGrid1.TableStyles.AddRange(new
System.Windows.Forms.DataGridTableStyle [] {
this.dataGridTableStyle1});
this.dataGrid1.Navigate + = new
System.Windows.Forms.NavigateEventHandler(this.dat aGrid1_Navigate);
//
// dataGridTableStyle1
//
this.dataGridTableStyle1.DataGrid = this.dataGrid1;
this.dataGridTableStyle1.GridColumnStyles.AddRange(new
System.Windows.Forms.DataGridColumnStyle [] {
this.dataGridTextBoxColumn1, this.dataGridTextBoxColumn2,
this.dataGridTextBoxColumn3,
this.dataGridTextBoxColumn4});
this.dataGridTableStyle1.HeaderForeColor =
System.Drawing.SystemColors.ControlText;
this .dataGridTableStyle1.MappingName =" p_getZipCodeData" ;;
// dataGridTextBoxColumn1
//
this.dataGridTextBoxColumn1.Format ="" ;;
this。 dataGridTextBoxColumn1.FormatInfo = null;
this.dataGridTextBoxColumn1.HeaderText =" Zip Code";
this.dataGridTextBoxColumn1.MappingName =" zip";
this.dataGridTextBoxColumn1.Width = 75;
//
// dataGridTextBoxColumn2
// this.dataGridTextBoxColumn2.Format ="" ;;
this.dataGridTextBoxColumn2.FormatInfo = null;
thi s.dataGridTextBoxColumn2.HeaderText =" City";
this.dataGridTextBoxColumn2.MappingName =" city";
this.dataGridTextBoxColumn2.Width = 75;
//
// dataGridTextBoxColumn3
// this.dataGridTextBoxColumn3.Format ="" ;;
this.dataGridTextBoxColumn3.FormatInfo = null;
this.dataGridTextBoxColumn3.HeaderText =" County";
this.dataGridTextBoxColumn3.MappingName =" county";
this.dataGridTextBoxColumn3.Width = 75;
// dataGridTextBoxColumn4
//
这个.dataGridTextBoxColumn4.Format ="" ;;
this.dataGridTextBoxColumn4.FormatInfo = null;
this.dataGridTextBoxColumn4.HeaderText =" State";
this.dataGridTextBoxColumn4.MappingName =" state" ;;
this.dataGridTextBoxColumn4.Width = 75;
//
// btnLoad
//
this.btnLoad.Location = new System.Drawing.Point( 472,8);
this.btnLoad.Name =" btnLoad";
this.btnLoad.TabIndex = 2;
this.btnLoad.Text =" Load";
this.btnLoad.C​​lick + = new System.EventHandler(this.btnLoad_Click);
//
// tboxLookupZipCode
//
this.tboxLookupZipCode.Location = new System.Drawing.Point(136,8);
this.tboxLookupZipCode.Name =" tboxLookupZipCode" ;;
this.tboxLookupZipCode.Size = new System.Drawing.Size(200,20);
this.tboxLookupZipCode.TabIndex = 1;
this.tboxLookupZipCode.Text ="" ;;
//
// lblLookupParameter
//
this.lblLookupParameter.Location = new System.Drawing.Point(24,8);
this.lblLookupParameter.Name = " lblLookupParameter";
this.lblLookupParameter.Size = new System.Drawing.Size(100,20);
this.lblLookupParameter.TabIndex = 3;
this.lblLookupParameter.Text =" ;邮政编码" ;;
this.lblLookupParameter.TextAlign =
System.Drawing.ContentAlignment.MiddleRight;
//
// btnOK
//
this.btnOK.D ialogResult = System.Windows.Forms.DialogResult.OK;
this.btnOK.Location = new System.Drawing.Point(378,352);
this.btnOK.Name =" btnOK";
this.btnOK.TabIndex = 3;
this.btnOK.Text =" OK";
this.btnOK.Click + = new System.EventHandler(this.btnOK_Click);
//
// btnCancel
//
this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.btnCancel.Location = new System.Drawing .Point(472,352);
this.btnCancel.Name =" btnCancel";
this.btnCancel.TabIndex = 4;
this.btnCancel.Text =" Cancel";
this.btnCancel.Click + = new System.EventHandler(this.btnCancel_Click);
//
// fclsLookup
//
this.AutoScaleBaseSize = new System .Drawing.Size(5,13);
this.ClientSize = new System.Drawing.Size(568,390);
this.Controls.Add(this.btnCancel);
this .Controls.Add(this.btnOK);
this.Controls.Add(this.lblLookupParameter);
this.Controls .Add(this.tboxLookupZipCode);
this.Controls.Add(this.btnLoad);
this.Controls.Add(this.dataGrid1);
this.Name =" fclsLookup" ;
this.Text =" Lookup";
((System.ComponentModel.ISupportInitialize)(this.d sLookup1))。EndInit();
((System.ComponentModel.ISupportInitialize) (this.d ataGrid1))。EndInit();
this.ResumeLayout(false);

}
#endregion

private void btnLoad_Click( object sender,System.EventArgs e)
{sqSelectCommand1.Parameters [" @ zip"]。Value = tboxLookupZipCode.Text;
dsLookup1.Clear();
sqlDataAdapter1。填充(dsLookup1);
}
私有空btnOK_Click(对象发送者,System.EventArgs e)
{

关闭();
}

private void btnCancel_Click(object sender,System.EventArgs e)
{
关闭();
}

私有空dataGrid1_Navigate(object sender,
System.Windows.Forms.NavigateEventArgs ne)
{

Clos e();
}

protected void dataGrid1_MouseDown(object sender,
System.Windows.Forms.MouseEventArgs e)
{
string strMessage = "TEST";

//strMessage = "Row: " + dataGrid1.HitTest(e.X,e.Y).Row.ToString();
int x = dataGrid1.HitTest(e.X, e.Y).Row;

strZipCode = dataGrid1[x, 0].ToString();
strZipCodeDtlId = dataGrid1[x, 3].ToString();
ZipCodeDtlId = strZipCodeDtlId;
MessageBox.Show(strZipCode);
MessageBox.Show("I still don’’t know what I’’m doing, but I’’m at " +
strMessage + ". I need to send back " + strZipCode);
}

}
}
I''m a rookie at C# and OO so please don''t laugh! I have a form
(fclsTaxCalculator) that contains a text box (tboxZipCode) containing a
zip
code. The user can enter a zip code in the text box and click a button to
determine whether the zip code is unique. If the zip code is not unique,
another form/dialog is displayed (fclsLookup) - lookup form/dialog. The
zip
code and zipid are both passed to the lookup form/dialog by reference. I
then load a datagrid with the possible matches (i.e. zip, city, county,
state, zipid).
When the user clicks the row in the datagrid, I want to pass the zipid
back
to the original form/dialog and run a stored procedure. My problem is I
do
not know how to get the ZipId back to the fclsTaxCalculator form/dialog.
I''ve not figured out how to set the variable that was passed in the
mousedown event. I''ve search for examples of this and I''ve not been able
to
track one down -
please help!!! My code is shown below:

//this is the event in the fclsTaxCalculator class that passes the ref
variables
private void lblZipCode_Click(object sender, System.EventArgs e)
{
strZipCode = tboxZip.Text;
fclsLookup objLookupForm = new fclsLookup(ref strZipCode, ref
strZipCodeDtlId);
objLookupForm.Show();
tboxZip.Text = strZipCode;
}

//this is the fclsLookup that receives the ref variable and I can''t figure
out how to
//set the variables to the selected value.

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;

namespace EnspireUtilities
{
/// <summary>
/// Summary description for Lookup.
/// </summary>
public class fclsLookup : System.Windows.Forms.Form
{
private System.Data.SqlClient.SqlDataAdapter sqlDataAdapter1;
private System.Data.SqlClient.SqlCommand sqlSelectCommand1;
private System.Data.SqlClient.SqlConnection sqlConnection1;
private EnspireUtilities.dsLookup dsLookup1;
private System.Windows.Forms.DataGrid dataGrid1;
private System.Windows.Forms.Button btnLoad;
private System.Windows.Forms.TextBox tboxLookupZipCode;
private System.Windows.Forms.Label lblLookupParameter;
private System.Windows.Forms.Button btnOK;
private System.Windows.Forms.Button btnCancel;
//private string strZipCode = string.Empty;
private System.Windows.Forms.DataGridTableStyle dataGridTableStyle1;
private System.Windows.Forms.DataGridTextBoxColumn dataGridTextBoxColumn1;
private System.Windows.Forms.DataGridTextBoxColumn dataGridTextBoxColumn2;
private System.Windows.Forms.DataGridTextBoxColumn dataGridTextBoxColumn3;
private System.Windows.Forms.DataGridTextBoxColumn dataGridTextBoxColumn4;
public string strZipCode = String.Empty;
public string strZipCodeDtlId = String.Empty;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;

public fclsLookup(ref string ZipCode, ref string ZipCodeDtlId)
{
//
// Required for Windows Form Designer support
//
InitializeComponent();

//
// TODO: Add any constructor code after InitializeComponent call
//
//tboxLookupZipCode.Text = ZipCode;
sqlSelectCommand1.Parameters["@zip"].Value = ZipCode;
dsLookup1.Clear();
sqlDataAdapter1.Fill(dsLookup1);
strZipCode = ZipCode;
strZipCodeDtlId = ZipCodeDtlId;
tboxLookupZipCode.Text = strZipCode;
this.dataGrid1.MouseDown += new
System.Windows.Forms.MouseEventHandler(this.dataGr id1_MouseDown);
}

/// <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.sqlDataAdapter1 = new System.Data.SqlClient.SqlDataAdapter();
this.sqlSelectCommand1 = new System.Data.SqlClient.SqlCommand();
this.sqlConnection1 = new System.Data.SqlClient.SqlConnection();
this.dsLookup1 = new EnspireUtilities.dsLookup();
this.dataGrid1 = new System.Windows.Forms.DataGrid();
this.dataGridTableStyle1 = new System.Windows.Forms.DataGridTableStyle();
this.dataGridTextBoxColumn1 = new
System.Windows.Forms.DataGridTextBoxColumn();
this.dataGridTextBoxColumn2 = new
System.Windows.Forms.DataGridTextBoxColumn();
this.dataGridTextBoxColumn3 = new
System.Windows.Forms.DataGridTextBoxColumn();
this.dataGridTextBoxColumn4 = new
System.Windows.Forms.DataGridTextBoxColumn();
this.btnLoad = new System.Windows.Forms.Button();
this.tboxLookupZipCode = new System.Windows.Forms.TextBox();
this.lblLookupParameter = new System.Windows.Forms.Label();
this.btnOK = new System.Windows.Forms.Button();
this.btnCancel = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.d sLookup1)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.d ataGrid1)).BeginInit();
this.SuspendLayout();
//
// sqlDataAdapter1
//
this.sqlDataAdapter1.SelectCommand = this.sqlSelectCommand1;
this.sqlDataAdapter1.TableMappings.AddRange(new
System.Data.Common.DataTableMapping[] {
new System.Data.Common.DataTableMapping("Table",
"p_getZipCodeData", new System.Data.Common.DataColumnMapping[] {
new
System.Data.Common.DataColumnMapping("zip", "zip"),
new
System.Data.Common.DataColumnMapping("city", "city"),
new
System.Data.Common.DataColumnMapping("county", "county"),
new
System.Data.Common.DataColumnMapping("state", "state"),
new
System.Data.Common.DataColumnMapping("zip_code_dtl _id",
"zip_code_dtl_id")})});
//
// sqlSelectCommand1
//
this.sqlSelectCommand1.CommandText = "[p_getZipCodeData]";
this.sqlSelectCommand1.CommandType =
System.Data.CommandType.StoredProcedure;
this.sqlSelectCommand1.Connection = this.sqlConnection1;
this.sqlSelectCommand1.Parameters.Add(new
System.Data.SqlClient.SqlParameter("@RETURN_VALUE" ,
System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.ReturnValue,
false, ((System.Byte)(0)), ((System.Byte)(0)), "",
System.Data.DataRowVersion.Current, null));
this.sqlSelectCommand1.Parameters.Add(new
System.Data.SqlClient.SqlParameter("@zip", System.Data.SqlDbType.VarChar,
10));
//
// sqlConnection1
//
this.sqlConnection1.ConnectionString = "workstation id=CENGENXP2;packet
size=4096;user id=sa;data source=cengenxp2;persis" +
"t security info=True;initial catalog=src;password=cocacola";
//
// dsLookup1
//
this.dsLookup1.DataSetName = "dsLookup";
this.dsLookup1.Locale = new System.Globalization.CultureInfo("en-US");
//
// dataGrid1
//
this.dataGrid1.DataMember = "p_getZipCodeData";
this.dataGrid1.DataSource = this.dsLookup1;
this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
this.dataGrid1.Location = new System.Drawing.Point(0, 40);
this.dataGrid1.Name = "dataGrid1";
this.dataGrid1.Size = new System.Drawing.Size(568, 288);
this.dataGrid1.TabIndex = 0;
this.dataGrid1.TableStyles.AddRange(new
System.Windows.Forms.DataGridTableStyle[] {
this.dataGridTableStyle1});
this.dataGrid1.Navigate += new
System.Windows.Forms.NavigateEventHandler(this.dat aGrid1_Navigate);
//
// dataGridTableStyle1
//
this.dataGridTableStyle1.DataGrid = this.dataGrid1;
this.dataGridTableStyle1.GridColumnStyles.AddRange (new
System.Windows.Forms.DataGridColumnStyle[] {
this.dataGridTextBoxColumn1,
this.dataGridTextBoxColumn2,
this.dataGridTextBoxColumn3,
this.dataGridTextBoxColumn4});
this.dataGridTableStyle1.HeaderForeColor =
System.Drawing.SystemColors.ControlText;
this.dataGridTableStyle1.MappingName = "p_getZipCodeData";
//
// dataGridTextBoxColumn1
//
this.dataGridTextBoxColumn1.Format = "";
this.dataGridTextBoxColumn1.FormatInfo = null;
this.dataGridTextBoxColumn1.HeaderText = "Zip Code";
this.dataGridTextBoxColumn1.MappingName = "zip";
this.dataGridTextBoxColumn1.Width = 75;
//
// dataGridTextBoxColumn2
//
this.dataGridTextBoxColumn2.Format = "";
this.dataGridTextBoxColumn2.FormatInfo = null;
this.dataGridTextBoxColumn2.HeaderText = "City";
this.dataGridTextBoxColumn2.MappingName = "city";
this.dataGridTextBoxColumn2.Width = 75;
//
// dataGridTextBoxColumn3
//
this.dataGridTextBoxColumn3.Format = "";
this.dataGridTextBoxColumn3.FormatInfo = null;
this.dataGridTextBoxColumn3.HeaderText = "County";
this.dataGridTextBoxColumn3.MappingName = "county";
this.dataGridTextBoxColumn3.Width = 75;
//
// dataGridTextBoxColumn4
//
this.dataGridTextBoxColumn4.Format = "";
this.dataGridTextBoxColumn4.FormatInfo = null;
this.dataGridTextBoxColumn4.HeaderText = "State";
this.dataGridTextBoxColumn4.MappingName = "state";
this.dataGridTextBoxColumn4.Width = 75;
//
// btnLoad
//
this.btnLoad.Location = new System.Drawing.Point(472, 8);
this.btnLoad.Name = "btnLoad";
this.btnLoad.TabIndex = 2;
this.btnLoad.Text = "Load";
this.btnLoad.Click += new System.EventHandler(this.btnLoad_Click);
//
// tboxLookupZipCode
//
this.tboxLookupZipCode.Location = new System.Drawing.Point(136, 8);
this.tboxLookupZipCode.Name = "tboxLookupZipCode";
this.tboxLookupZipCode.Size = new System.Drawing.Size(200, 20);
this.tboxLookupZipCode.TabIndex = 1;
this.tboxLookupZipCode.Text = "";
//
// lblLookupParameter
//
this.lblLookupParameter.Location = new System.Drawing.Point(24, 8);
this.lblLookupParameter.Name = "lblLookupParameter";
this.lblLookupParameter.Size = new System.Drawing.Size(100, 20);
this.lblLookupParameter.TabIndex = 3;
this.lblLookupParameter.Text = "Zip Code";
this.lblLookupParameter.TextAlign =
System.Drawing.ContentAlignment.MiddleRight;
//
// btnOK
//
this.btnOK.DialogResult = System.Windows.Forms.DialogResult.OK;
this.btnOK.Location = new System.Drawing.Point(378, 352);
this.btnOK.Name = "btnOK";
this.btnOK.TabIndex = 3;
this.btnOK.Text = "OK";
this.btnOK.Click += new System.EventHandler(this.btnOK_Click);
//
// btnCancel
//
this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.btnCancel.Location = new System.Drawing.Point(472, 352);
this.btnCancel.Name = "btnCancel";
this.btnCancel.TabIndex = 4;
this.btnCancel.Text = "Cancel";
this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click);
//
// fclsLookup
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(568, 390);
this.Controls.Add(this.btnCancel);
this.Controls.Add(this.btnOK);
this.Controls.Add(this.lblLookupParameter);
this.Controls.Add(this.tboxLookupZipCode);
this.Controls.Add(this.btnLoad);
this.Controls.Add(this.dataGrid1);
this.Name = "fclsLookup";
this.Text = "Lookup";
((System.ComponentModel.ISupportInitialize)(this.d sLookup1)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.d ataGrid1)).EndInit();
this.ResumeLayout(false);

}
#endregion
private void btnLoad_Click(object sender, System.EventArgs e)
{
sqlSelectCommand1.Parameters["@zip"].Value = tboxLookupZipCode.Text;
dsLookup1.Clear();
sqlDataAdapter1.Fill(dsLookup1);
}

private void btnOK_Click(object sender, System.EventArgs e)
{

Close();
}

private void btnCancel_Click(object sender, System.EventArgs e)
{
Close();
}

private void dataGrid1_Navigate(object sender,
System.Windows.Forms.NavigateEventArgs ne)
{

Close();
}

protected void dataGrid1_MouseDown(object sender,
System.Windows.Forms.MouseEventArgs e)
{
string strMessage = "TEST";

//strMessage = "Row: " + dataGrid1.HitTest(e.X,e.Y).Row.ToString();
int x = dataGrid1.HitTest(e.X, e.Y).Row;

strZipCode = dataGrid1[x, 0].ToString();
strZipCodeDtlId = dataGrid1[x, 3].ToString();
ZipCodeDtlId = strZipCodeDtlId;
MessageBox.Show(strZipCode);
MessageBox.Show("I still don''t know what I''m doing, but I''m at " +
strMessage + ". I need to send back " + strZipCode);
}

}
}



Jeff,


I’’m sorry but I don’’t understand how to implement your suggestion. Are you

suggesting that I create a new class called MyClass with a method called

LookupDone in it? Also, I’’ve never used a structure. Which Class should the

structure be in? I know, you’’re thinking - he is a rookie. I do appreciate

your help though.


Thanks,

Johnny


"Jeff Louie" wrote:
Jeff,

I''m sorry but I don''t understand how to implement your suggestion. Are you
suggesting that I create a new class called MyClass with a method called
LookupDone in it? Also, I''ve never used a structure. Which Class should the
structure be in? I know, you''re thinking - he is a rookie. I do appreciate
your help though.

Thanks,
Johnny

"Jeff Louie" wrote:
Hmm...
MyClass
LookupDone(object sender, object myArgs);

fclsLookup objLookupForm = new fclsLookup(MyClass this, strZipCode,
strZipCodeDtlId)
...

FCLSLookup
...
myClass.LookupDone(this,myArgs);

// immutable readonly structure or class
struct myArgs {
private zip;
public string Zip {
get {return this.zip;}
}
}
Regards,
Jeff

*** Sent via Developersdex http://www.developersdex.com ***
Don’’t just participate in USENET...get rewarded for it!
Hmm...
MyClass
LookupDone(object sender, object myArgs);

fclsLookup objLookupForm = new fclsLookup(MyClass this, strZipCode,
strZipCodeDtlId)
...

FCLSLookup
...
myClass.LookupDone(this,myArgs);

// immutable readonly structure or class
struct myArgs {
private zip;
public string Zip {
get {return this.zip;}
}
}
Regards,
Jeff

*** Sent via Developersdex http://www.developersdex.com ***
Don''t just participate in USENET...get rewarded for it!



这篇关于在表单类之间传递参数 - C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆