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. C#
  4. How do I change a control's content through the Controls collection?

How do I change a control's content through the Controls collection?

Scheduled Pinned Locked Moved C#
questiondatabasec++wpfwcf
3 Posts 2 Posters 0 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.
  • D Offline
    D Offline
    David Fleming
    wrote on last edited by
    #1

    Here are two different code approaches I have used, but neither works.

    int i = thisForm.GetChildIndex(textBox);
    thisForm.Controls[index].Text = "Something";
    thisForm.Controls[index].Invalidate();

    and

    Control controlTest = thisForm.textBox;
    controlTest.Text = "Something";
    controlTest.Invalidate();

    The reason I'm trying to do this is that I would like to be able to "map" controls to fields in a database (I'd like to do it myself rather than do data-binding), so I need a way to be able to create a list (or other collection) of controls and the data field to put in that control. It is rather like UpdateData in VC++. But I can't seem to update the screen with code like what I've shown above. How do I go about this? I hope the question makes sense because I'm sure one of you guys knows how to do it if I can just figure the right way to ask the question. Thanks.

    C 1 Reply Last reply
    0
    • D David Fleming

      Here are two different code approaches I have used, but neither works.

      int i = thisForm.GetChildIndex(textBox);
      thisForm.Controls[index].Text = "Something";
      thisForm.Controls[index].Invalidate();

      and

      Control controlTest = thisForm.textBox;
      controlTest.Text = "Something";
      controlTest.Invalidate();

      The reason I'm trying to do this is that I would like to be able to "map" controls to fields in a database (I'd like to do it myself rather than do data-binding), so I need a way to be able to create a list (or other collection) of controls and the data field to put in that control. It is rather like UpdateData in VC++. But I can't seem to update the screen with code like what I've shown above. How do I go about this? I hope the question makes sense because I'm sure one of you guys knows how to do it if I can just figure the right way to ask the question. Thanks.

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      I wonder if you need to cast it to be a textbox first ?

      Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

      D 1 Reply Last reply
      0
      • C Christian Graus

        I wonder if you need to cast it to be a textbox first ?

        Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

        D Offline
        D Offline
        David Fleming
        wrote on last edited by
        #3

        Thanks for the suggestion, but it turns out the problem was something totally different. The textbox in question is part of a CustomControl, and when I declared the public Attribute for Text I accidentally used the "new" keyword instead of "override". So, when I set .Text for the control, it was not actually setting the .Text for the TextBox part of the CustomControl like it was supposed to. Turns out the code snippet I put in my original message DOES work just fine. Thanks anyway for the response.

        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