Databinding to TextBox
-
Hi everybody, I'm trying to bind a class variable to a textbox. the data class looks like:
public class route { public string name { get; set; } public int adress { get; set; } public route() { name = ""; adress = 0; } } public class adr { public int index { get; set; } public route r1 { get; set; } public route r2 { get; set; } public adr() { index = 0; r1 = new route(); r2 = new route(); } } public class para { public int i1 { get; set; } public int i2 { get; set; } } public class adrData { public string label { get; set; } public adr ad { get; set; } public para pa { get; set; } }
When I try to bind f.e. ad.r1.name to a textbox text via designer, it offers only label, ad and pa for binding. What am I missing here? Thnx adv for your answers.
-
Hi everybody, I'm trying to bind a class variable to a textbox. the data class looks like:
public class route { public string name { get; set; } public int adress { get; set; } public route() { name = ""; adress = 0; } } public class adr { public int index { get; set; } public route r1 { get; set; } public route r2 { get; set; } public adr() { index = 0; r1 = new route(); r2 = new route(); } } public class para { public int i1 { get; set; } public int i2 { get; set; } } public class adrData { public string label { get; set; } public adr ad { get; set; } public para pa { get; set; } }
When I try to bind f.e. ad.r1.name to a textbox text via designer, it offers only label, ad and pa for binding. What am I missing here? Thnx adv for your answers.
What type is "ad.r1.name"? As far as I can see from your code, there's only one "name" property, and that's a string, whereas the bindin-options imply that "name" contains an
adrData
?Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]
-
What type is "ad.r1.name"? As far as I can see from your code, there's only one "name" property, and that's a string, whereas the bindin-options imply that "name" contains an
adrData
?Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]
its a tree structure: the string name is an element of class route, route r1 is an element of class adr, adr ad is an element of class adrData.
-
Hi everybody, I'm trying to bind a class variable to a textbox. the data class looks like:
public class route { public string name { get; set; } public int adress { get; set; } public route() { name = ""; adress = 0; } } public class adr { public int index { get; set; } public route r1 { get; set; } public route r2 { get; set; } public adr() { index = 0; r1 = new route(); r2 = new route(); } } public class para { public int i1 { get; set; } public int i2 { get; set; } } public class adrData { public string label { get; set; } public adr ad { get; set; } public para pa { get; set; } }
When I try to bind f.e. ad.r1.name to a textbox text via designer, it offers only label, ad and pa for binding. What am I missing here? Thnx adv for your answers.
First, I think you need to add a constructor to 'adrData:
public class adrData
{
public string label { get; set; }
public adr ad { get; set; }
public para pa { get; set; }// ctor public adrData() { label = ""; ad = new adr(); pa = new para(); }
}
Then, in code, you can do something like this:
adrData newAdrData = new adrData();
newAdrData.ad.r1.name = "Route Name #1";
textBox1.DataBindings.Add("Text", newAdrData, "ad.r1.name");
To bind to a specific instance of 'adrData. Unless you create a new instance of 'ad, within 'adrData, then you never initialize the 'routes: because only creating a new instance of 'adr will initialize the 'routes.
~ “This isn't right; this isn't even wrong." Wolfgang Pauli, commenting on a physics paper submitted for a journal