Can this be done?

I know you can databind to form controls, but what about object properties?

For example, I have a form that has two functions, to edit a record and to create a new record, but the problem is that in order to create a new record you need a reference to another record (FK) but the user shouldn't have to "pick" that in the editor, instead they have already done that by opening the editor within a certain record already. I just pass the FK to the editor as a constructor parameter. I need to databind to that so when the user saves the record the FK is already there.

I have it working now by binding to a label, but when I set the label property to "Visible = false" it doesn't work and the binding fails.

I don't really want the user to have to stare at an irrelevant (to them) number that references the FK.

Any ideas?

Have you tried do the binding to a HiddenField?

Hidden field?

This is a windows app not a web app sorry I should have clarified.

Oh ok, I guess I'm sorry too for guessing!!!!

I don't do too much windows app coding, but sometimes i have to do easy stuff, and when i want to share a variable i do this.

private static string test;

public static string Test
{
    get { return ThisAddIn.test; }
    set { ThisAddIn.test = value; }
}

//Where ThisAddIn is the name of the class
//and to retrieve that info from another window
String test = ThisAddIn.Test;

//This might not be the best solution, I don't do Win app coding but that have helped me before.
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.