Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Windows Forms
  4. Databinding to TextBox

Databinding to TextBox

Scheduled Pinned Locked Moved Windows Forms
databasewpfwcfquestion
4 Posts 3 Posters 5 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W Offline
    W Offline
    Wild Thing
    wrote on last edited by
    #1

    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.

    L B 2 Replies Last reply
    0
    • W Wild Thing

      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.

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      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[^]

      W 1 Reply Last reply
      0
      • L Lost User

        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[^]

        W Offline
        W Offline
        Wild Thing
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        • W Wild Thing

          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.

          B Offline
          B Offline
          BillWoodruff
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups