如何从表单返回中获取数据 [英] how to get data from Form returning

查看:141
本文介绍了如何从表单返回中获取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我有一个具有按钮的ManageItemForm(itemLookup).

我想单击此按钮,然后调用另一个表单(即ItemLookup Form),并且该表单具有一个DataGridView,其中包含Items信息.

我希望当我单击按钮时(即在ManageItemForm上)它应该调用ItemLookup表单,并且当我双击datagridview中的一个项目时,它应该将该项目返回到ManageItem表单.

我应该如何从itemLookup表单中获取该项目?


实际上,我正在开发一个具有ManageItem Form的项目,该表单包含带有项目名称的项目列表.
ManageItem表单包含一个名为LookItemButton的按钮.
在此按钮的单击事件中,我有另一个表单的对象(即ItemLookUpForm),并且该表单包含一个datagrid视图,该视图显示了所有具有其他信息的项目.

我希望当我双击DataGridView时,选定的项目应返回到ManagItemForm,并且ItemLookUp窗体应关闭或隐藏.

Hi to all,

I have ManageItemForm having a button(itemLookup).

I want to click this button and call another form (ie. ItemLookup Form ) and that form having a DataGridView which contains Items information.

I want that when I click the button (ie. on ManageItemForm) it should call the ItemLookup Form and when I double click on an item in the datagridview it should return that item back to the ManageItem form.

How should I get that item from itemLookup form?


Actually I''m working on a project having ManageItem Form which contains a List of Items with the name of items.
The ManageItem form conatains a button with name LookItemButton.
At the click event of this button I have an object of another form (i.e ItemLookUpForm) and that form contains a datagrid view which shows all the item with other information.

I want that when I double Click on DataGridView the selected item should returnback to ManagItemForm, and the ItemLookUp Form should be closed or hidden.

推荐答案

通常,我给出对话框形式类的方法和属性是这样的:

Typically I give the dialog form class a method and property something like this:

public BusinessObject BusinessObject {
 get { return businessObject; }
 set { businessObject = value; UpdateUI(value); }
}
private BusinessObject businessObject;

DialogResult Edit(BusinessObject obj){
 this.BusinessObject = obj;
 DialogResult r = this.ShowDialog();
 if(r == DialogResult.OK){
  WriteBackTo(BusinessObject);
 }
}



然后,调用表单会执行类似的操作



The calling form then does something like

if(DialogResult.OK == myEditorForm.Edit(myObject)){
 myObject = myEditorForm.BusinessObject;
 // Or: myEditorForm.BusinessObject.CopyTo(myObject);
}


在您要保留相同的对象引用但设置所有属性的情况下,可以使用这些选项.显然,BusinessObject是您要编辑的任何内容的占位符,而UpdateUI是您需要编写的方法,该方法可以为该实例的实例设置编辑器表单. (您可以进行数据绑定,但是需要绑定到对象的副本或保留更改历史记录的代理,因为您需要能够取消更改.)

错过了一步.更新了编辑. WriteBackTo与UpdateUI相反,它采用在表单上输入的值并将其放回对象中.如果您选择将对话框数据绑定到副本或代理,则无需这样做.通常,我不绑定简单对话框的数据,因为与手动重写属性值相比,制作代理更费力.


The options there are for the case where you want to preserve the same object reference but set all the properties. Obviously, BusinessObject is a placeholder for whatever you want to edit, and UpdateUI is a method you need to write which sets the editor form up for this instance of one. (You can data bind, but you need to bind to a copy of the object or a change-history-preserving proxy for it, because you need to be able to cancel the changes.)

missed a step. Updated Edit. WriteBackTo is the opposite of UpdateUI, it takes the values entered on the form and puts it back in the object. If you choose to data bind the dialog to a copy or proxy then you don''t need to do that. Typically I don''t data bind simple dialogs because making the proxy is more effort than rewriting the property values manually.


//从主页调用此函数..

函数openLookup(targetField,windowpage)
{
//Call this function from main page..

function openLookup(targetField,windowpage)
{
var w = window.open(windowpage,'BCFSYS','width=572,height=550,scrollbars=1,resizable=no,top=100,left=200');
w.targetField = targetField; //create target field variable in popup window with the passed targetField as value

w.focus();
return false;



}

//在查找页面中,使用以下javascript函数将选择的值返回给主页.



}

// in lookup page use following javascript function to return back selected value to the main page.

function setValue(val)
{
if (opener && !opener.closed && opener.setTargetField)
{
window.opener.document.getElementById('ctl00_ContentPlaceHolder1_txtDepart').value val;
window.close();
window.opener.setTargetField(window.opener.document.getElementById('ctl00_ContentPlaceHolder1_txtDepart'), val);}
self.close();
}



在查找页面的gridview的rowdatabound事件中,单击gridview行时设置setValue函数调用..



In rowdatabound event of gridview in lookup page, set setValue function call on click of gridview row..


您是否了解 ^ ]?


这篇关于如何从表单返回中获取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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