|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Datagrid doesn't reflect changes in datasourceDear all,
when I fill my dataset the datagrid doesn't reflect these changes. Here's the scenario - add new form - add datagrid to form - add dataset to form - bind datagrid to dataset (using datagrid properties) - next code is generated in InitializeComponent() -> dataset is created, datasource is set. - next I fill the dataset (Form1_Load) - run -> datagrid is empty. I don't like to use dataGrid.Datasource = ... again. Any ideas? René Rene -
I'm pretty sure that setting the DataSource property for the DataGrid before populating the DataSet won't get you there. You'll have to move your DataSource-setting code out of InitializeComponent() and after you populate the DataSet in Form_Load. Sorry. - Scott Show quote "René Titulaer" <RenTitul***@discussions.microsoft.com> wrote in message news:3480B478-BDD9-4538-8101-3145BB65324C@microsoft.com... > Dear all, > > when I fill my dataset the datagrid doesn't reflect these changes. > > Here's the scenario > - add new form > - add datagrid to form > - add dataset to form > - bind datagrid to dataset (using datagrid properties) > - next code is generated in InitializeComponent() -> dataset is created, > datasource is set. > - next I fill the dataset (Form1_Load) > - run -> datagrid is empty. > > I don't like to use dataGrid.Datasource = ... again. > > Any ideas? > René I think I get crazy.
It works now. I did configure everything via the designer so everything is in InitializeComponent(). In Form1_Load I fill the dataset and it works? Beats me. If you don't believe me ;-) using System; using System.IO; using System.Xml; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; using System.Runtime.Remoting; using System.Runtime.Remoting.Channels; using System.Runtime.Remoting.Channels.Http; using System.Runtime.Remoting.Channels.Tcp; using System.Globalization; using RJDServerObjects; namespace RJDClient { /// <summary> /// Summary description for Form1. /// </summary> public class Form1 : System.Windows.Forms.Form { private System.Windows.Forms.Button button1; private System.Windows.Forms.DataGrid dataGrid1; private System.Windows.Forms.Button button2; private System.Windows.Forms.Button button3; private System.Windows.Forms.Label label1; private System.Windows.Forms.TextBox textBox1; private System.Windows.Forms.TextBox textBox2; private System.Windows.Forms.Label label2; private System.Windows.Forms.Label label3; private System.Windows.Forms.Label label4; private System.Windows.Forms.TextBox textBox3; private Definitions.Tasks tasks1; /// <summary> /// Required designer variable. /// </summary> private System.ComponentModel.Container components = null; public Form1() { // // Required for Windows Form Designer support // InitializeComponent(); } /// <summary> /// Clean up any resources being used. /// </summary> protected override void Dispose( bool disposing ) { if( disposing ) { if (components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Windows Form Designer generated code /// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { this.button1 = new System.Windows.Forms.Button(); this.dataGrid1 = new System.Windows.Forms.DataGrid(); this.tasks1 = new Definitions.Tasks(); this.button2 = new System.Windows.Forms.Button(); this.button3 = new System.Windows.Forms.Button(); this.label1 = new System.Windows.Forms.Label(); this.textBox1 = new System.Windows.Forms.TextBox(); this.textBox2 = new System.Windows.Forms.TextBox(); this.label2 = new System.Windows.Forms.Label(); this.label3 = new System.Windows.Forms.Label(); this.label4 = new System.Windows.Forms.Label(); this.textBox3 = new System.Windows.Forms.TextBox(); ((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.tasks1)).BeginInit(); this.SuspendLayout(); // // button1 // this.button1.Location = new System.Drawing.Point(680, 72); this.button1.Name = "button1"; this.button1.Size = new System.Drawing.Size(120, 40); this.button1.TabIndex = 0; this.button1.Text = "Show using web services"; this.button1.Click += new System.EventHandler(this.button1_Click); // // dataGrid1 // this.dataGrid1.DataMember = "Task"; this.dataGrid1.DataSource = this.tasks1; this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText; this.dataGrid1.Location = new System.Drawing.Point(56, 56); this.dataGrid1.Name = "dataGrid1"; this.dataGrid1.Size = new System.Drawing.Size(584, 224); this.dataGrid1.TabIndex = 1; this.dataGrid1.MouseUp += new System.Windows.Forms.MouseEventHandler(this.dataGrid1_MouseUp); // // tasks1 // this.tasks1.DataSetName = "Tasks"; this.tasks1.EnforceConstraints = false; this.tasks1.Locale = new System.Globalization.CultureInfo("en-US"); // // button2 // this.button2.Location = new System.Drawing.Point(680, 136); this.button2.Name = "button2"; this.button2.Size = new System.Drawing.Size(120, 40); this.button2.TabIndex = 2; this.button2.Text = "Show using remoting"; this.button2.Click += new System.EventHandler(this.button2_Click); // // button3 // this.button3.Location = new System.Drawing.Point(680, 200); this.button3.Name = "button3"; this.button3.Size = new System.Drawing.Size(96, 24); this.button3.TabIndex = 3; this.button3.Text = "Clear"; this.button3.Click += new System.EventHandler(this.button3_Click); // // label1 // this.label1.Location = new System.Drawing.Point(304, 16); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(200, 23); this.label1.TabIndex = 4; this.label1.Text = "label1"; // // textBox1 // this.textBox1.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.tasks1, "Task.Tsno")); this.textBox1.Location = new System.Drawing.Point(240, 296); this.textBox1.Name = "textBox1"; this.textBox1.TabIndex = 5; this.textBox1.Text = ""; // // textBox2 // this.textBox2.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.tasks1, "Task.Tsno")); this.textBox2.Location = new System.Drawing.Point(240, 328); this.textBox2.Name = "textBox2"; this.textBox2.TabIndex = 6; this.textBox2.Text = ""; // // label2 // this.label2.Location = new System.Drawing.Point(56, 296); this.label2.Name = "label2"; this.label2.TabIndex = 7; this.label2.Text = "label2"; // // label3 // this.label3.Location = new System.Drawing.Point(56, 328); this.label3.Name = "label3"; this.label3.TabIndex = 8; this.label3.Text = "label3"; // // label4 // this.label4.Location = new System.Drawing.Point(56, 368); this.label4.Name = "label4"; this.label4.TabIndex = 9; this.label4.Text = "label4"; // // textBox3 // this.textBox3.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.tasks1, "Task.Tsty")); this.textBox3.Location = new System.Drawing.Point(240, 376); this.textBox3.Name = "textBox3"; this.textBox3.TabIndex = 10; this.textBox3.Text = ""; // // Form1 // this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); this.ClientSize = new System.Drawing.Size(848, 525); this.Controls.Add(this.textBox3); this.Controls.Add(this.label4); this.Controls.Add(this.label3); this.Controls.Add(this.label2); this.Controls.Add(this.textBox2); this.Controls.Add(this.textBox1); this.Controls.Add(this.label1); this.Controls.Add(this.button3); this.Controls.Add(this.button2); this.Controls.Add(this.dataGrid1); this.Controls.Add(this.button1); this.Name = "Form1"; this.Text = "Form1"; this.Load += new System.EventHandler(this.Form1_Load); ((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.tasks1)).EndInit(); this.ResumeLayout(false); } #endregion /// <summary> /// The main entry point for the application. /// </summary> [STAThread] static void Main() { Application.Run(new Form1()); RemotingConfiguration.Configure("RJDClient.exe.config"); AppDomain.CurrentDomain.SetPrincipalPolicy(System.Security.Principal.PrincipalPolicy.WindowsPrincipal); } private void button1_Click(object sender, System.EventArgs e) { } private void Changed(object sender, System.EventArgs e) { } private void button2_Click(object sender, System.EventArgs e) { // if (ChannelServices.RegisteredChannels.Length == 0) // { // //HttpChannel channel = new HttpChannel(); // TcpChannel channel = new TcpChannel(); // // ChannelServices.RegisterChannel(channel); // } // // IPersonalTasks tasks = (IPersonalTasks) Activator.GetObject(typeof(IPersonalTasks), "tcp://134.188.56.143:1234/PersonalTasks.rem"); // //// string msg = tasks.GetAll(); //// //// Definitions.Tasks data = new Definitions.Tasks(); //// //// StringReader reader = new StringReader(msg); //// //// data.ReadXml(reader, XmlReadMode.Auto); // // Definitions.Tasks data = tasks.GetAll(); // // dataGrid1.DataSource = data.Task; // // label1.Text = "Number of records: " + data.Task.Rows.Count.ToString(); } private void button3_Click(object sender, System.EventArgs e) { dataGrid1.DataSource = null; } private void Form1_Load(object sender, System.EventArgs e) { RJDWebServices.PersonalTasks tasks = new RJDWebServices.PersonalTasks(); string rawdata = tasks.GetAll(); StringReader reader = new StringReader(rawdata); tasks1.ReadXml(reader, XmlReadMode.Auto); label1.Text = "Number of records: " + tasks1.Task.Rows.Count.ToString(); } private void dataGrid1_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e) { Point pt = new Point(e.X, e.Y); DataGrid.HitTestInfo hit = dataGrid1.HitTest(pt); if (hit.Type == DataGrid.HitTestType.Cell) { dataGrid1.CurrentCell = new DataGridCell(hit.Row, hit.Column); dataGrid1.Select(hit.Row); } } } } Show quote "Scott McChesney" wrote: > Rene - > > I'm pretty sure that setting the DataSource property for the DataGrid before > populating the DataSet won't get you there. You'll have to move your > DataSource-setting code out of InitializeComponent() and after you populate > the DataSet in Form_Load. Sorry. > > - Scott > > "René Titulaer" <RenTitul***@discussions.microsoft.com> wrote in message > news:3480B478-BDD9-4538-8101-3145BB65324C@microsoft.com... > > Dear all, > > > > when I fill my dataset the datagrid doesn't reflect these changes. > > > > Here's the scenario > > - add new form > > - add datagrid to form > > - add dataset to form > > - bind datagrid to dataset (using datagrid properties) > > - next code is generated in InitializeComponent() -> dataset is created, > > datasource is set. > > - next I fill the dataset (Form1_Load) > > - run -> datagrid is empty. > > > > I don't like to use dataGrid.Datasource = ... again. > > > > Any ideas? > > René > > > |
|||||||||||||||||||||||