Click here to Skip to main content
15,923,789 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
Posted
Updated 27-May-11 0:36am
v2
Comments
Dalek Dave 27-May-11 6:36am    
Edited for Grammar, Syntax, Spelling and Readability.

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);
}

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.)

Edit: 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.
 
Share this answer
 
v2
Comments
Dalek Dave 27-May-11 6:36am    
Good Answer.
//Call this function from main page..

function openLookup(targetField,windowpage)
{
C#
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;


}

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

C#
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();
}


In rowdatabound event of gridview in lookup page, set setValue function call on click of gridview row..
 
Share this answer
 
Comments
Dalek Dave 27-May-11 6:37am    
Gets a 5.
BobJanova 27-May-11 11:12am    
I'm fairly sure that this question is about WinForms not a web app, the word Form is not used (at least not in this context) there.
Are you aware of the principle of injection[^]?
 
Share this answer
 
v2
Comments
Dalek Dave 27-May-11 6:36am    
Good Link
StM0n 27-May-11 6:40am    
Oops... so much for copy & paste... ;)
Muhammad Tufail 1979 27-May-11 8:43am    
no sorry i dont know about injection...
StM0n 27-May-11 10:17am    
Maybe you should check this prinicple out... it could be usefull.
BobJanova 27-May-11 11:12am    
I don't see how dependency injection is related to this question.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900