Click here to Skip to main content
15,887,683 members
Home / Discussions / C#
   

C#

 
AnswerRe: Split Name Field Pin
V.5-Nov-09 4:21
professionalV.5-Nov-09 4:21 
AnswerRe: Split Name Field Pin
PIEBALDconsult5-Nov-09 5:34
mvePIEBALDconsult5-Nov-09 5:34 
GeneralRe: Split Name Field Pin
Luc Pattyn5-Nov-09 12:51
sitebuilderLuc Pattyn5-Nov-09 12:51 
QuestionHow to Hide MenuBar/ToolBar while displaying Office Document using Web Browser? Pin
muhammad_umair5-Nov-09 1:22
muhammad_umair5-Nov-09 1:22 
QuestionIs there a better way for updating bound controls when updating the data source manually? Pin
TheFoZ5-Nov-09 0:40
TheFoZ5-Nov-09 0:40 
AnswerRe: Is there a better way for updating bound controls when updating the data source manually? Pin
Gerry Schmitz5-Nov-09 15:34
mveGerry Schmitz5-Nov-09 15:34 
GeneralRe: Is there a better way for updating bound controls when updating the data source manually? Pin
TheFoZ5-Nov-09 22:23
TheFoZ5-Nov-09 22:23 
GeneralRe: Is there a better way for updating bound controls when updating the data source manually? Pin
Gerry Schmitz6-Nov-09 6:57
mveGerry Schmitz6-Nov-09 6:57 
Sorry about that; didn't realize those methods were protected.

Here is a solution that works: use the DataBindings ReadValue and WriteValue methods; eg.


<pre>using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1 {
   public partial class Form1 : Form {

         private TextBox fistNameTextBox =
            new TextBox() { Location = new Point( 0, 0 ) };
         private TextBox lastNameTextBox =
            new TextBox() { Location = new Point( 0, 30 ) };

         private Button readButtom = new Button() {
            Location = new Point( 0, 70 ),
            AutoSize = true,
            Text = "Read from Source"
         };

         private Person aPerson = new Person();

         public Form1() {

            readButtom.Click += new EventHandler( readButtom_Click );

            fistNameTextBox.DataBindings.Add( new Binding( "Text", aPerson, "FirstName" ) );
            lastNameTextBox.DataBindings.Add( new Binding( "Text", aPerson, "LastName" ) );

            this.Controls.AddRange( new Control[] {
                  fistNameTextBox, lastNameTextBox, readButtom } );
         }

         void readButtom_Click( object sender, EventArgs e ) {

            aPerson.FirstName = "John";
            aPerson.LastName = "Smith";

            foreach ( Control control in this.FindForm().Controls ) {
                  if ( control is TextBox && control.DataBindings.Count > 0 )
                     control.DataBindings[ 0 ].ReadValue();
            }
         }

         [STAThread]
         static void Main() {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault( false );
            Application.Run( new Form1() );
         }

         public class Person {
            public string FirstName { get; set; }
            public string LastName { get; set; }
         }
   }
}</pre>
AnswerRe: Is there a better way for updating bound controls when updating the data source manually? Pin
TheFoZ9-Nov-09 23:13
TheFoZ9-Nov-09 23:13 
Generalcasting struct to list<object></object> Pin
manowj4-Nov-09 23:43
manowj4-Nov-09 23:43 
GeneralRe: casting struct to list Pin
OriginalGriff5-Nov-09 0:14
mveOriginalGriff5-Nov-09 0:14 
GeneralRe: casting struct to list [modified] Pin
manowj5-Nov-09 0:35
manowj5-Nov-09 0:35 
GeneralRe: casting struct to list Pin
OriginalGriff5-Nov-09 0:53
mveOriginalGriff5-Nov-09 0:53 
QuestionRead text from notepad in c# Pin
krinaljariwala4-Nov-09 22:43
krinaljariwala4-Nov-09 22:43 
AnswerRe: Read text from notepad in c# Pin
Covean4-Nov-09 23:16
Covean4-Nov-09 23:16 
GeneralRe: Read text from notepad in c# Pin
krinaljariwala4-Nov-09 23:38
krinaljariwala4-Nov-09 23:38 
GeneralRe: Read text from notepad in c# Pin
Covean4-Nov-09 23:44
Covean4-Nov-09 23:44 
GeneralRe: Read text from notepad in c# Pin
krinaljariwala5-Nov-09 0:04
krinaljariwala5-Nov-09 0:04 
QuestionExplanation on "DSO" Pin
Joe Rozario4-Nov-09 22:25
Joe Rozario4-Nov-09 22:25 
AnswerMessage Closed Pin
4-Nov-09 22:30
stancrm4-Nov-09 22:30 
GeneralRe: Explanation on "DSO" Pin
Joe Rozario4-Nov-09 22:40
Joe Rozario4-Nov-09 22:40 
GeneralMessage Closed Pin
4-Nov-09 22:43
stancrm4-Nov-09 22:43 
GeneralRe: Explanation on "DSO" Pin
Joe Rozario4-Nov-09 22:56
Joe Rozario4-Nov-09 22:56 
GeneralMessage Closed Pin
4-Nov-09 23:02
stancrm4-Nov-09 23:02 
GeneralRe: Explanation on "DSO" Pin
Joe Rozario4-Nov-09 23:24
Joe Rozario4-Nov-09 23:24 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.