Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Get grid's column widths
Message
De
20/11/2004 17:26:58
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
Information générale
Forum:
ASP.NET
Catégorie:
Formulaires
Divers
Thread ID:
00962477
Message ID:
00963243
Vues:
7
>Cetin,
>Yes please post some sample C# code.

OK here it's (using VFP data as I know you've it):
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace WindowsApplication2
{
	/// <summary>
	/// Summary description for Form1.
	/// </summary>
	public class Form1 : System.Windows.Forms.Form
	{
		private System.Data.OleDb.OleDbDataAdapter oleDbDataAdapter1;
		private System.Data.OleDb.OleDbCommand oleDbSelectCommand1;
		private System.Data.OleDb.OleDbConnection oleDbConnection1;
		private System.Windows.Forms.DataGrid dataGrid1;
		private System.Windows.Forms.DataGridTableStyle dataGridTableStyle1;
		private System.Windows.Forms.DataGridTextBoxColumn dataGridTextBoxColumn1;
		private System.Windows.Forms.DataGridTextBoxColumn dataGridTextBoxColumn2;
		private System.Windows.Forms.DataGridTextBoxColumn dataGridTextBoxColumn3;
		private System.Windows.Forms.Button button2;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		public Form1()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			//
			// TODO: Add any constructor code after InitializeComponent call
			//
		}

		/// <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.oleDbDataAdapter1 = new System.Data.OleDb.OleDbDataAdapter();
			this.oleDbSelectCommand1 = new System.Data.OleDb.OleDbCommand();
			this.oleDbConnection1 = new System.Data.OleDb.OleDbConnection();
			this.dataGrid1 = new System.Windows.Forms.DataGrid();
			this.dataGridTableStyle1 = new System.Windows.Forms.DataGridTableStyle();
			this.dataGridTextBoxColumn1 = new System.Windows.Forms.DataGridTextBoxColumn();
			this.dataGridTextBoxColumn2 = new System.Windows.Forms.DataGridTextBoxColumn();
			this.dataGridTextBoxColumn3 = new System.Windows.Forms.DataGridTextBoxColumn();
			this.button2 = new System.Windows.Forms.Button();
			this.custData1 = new WindowsApplication6.custData();
			((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.custData1)).BeginInit();
			this.SuspendLayout();
			// 
			// oleDbDataAdapter1
			// 
			this.oleDbDataAdapter1.SelectCommand = this.oleDbSelectCommand1;
			this.oleDbDataAdapter1.TableMappings.AddRange(new System.Data.Common.DataTableMapping[] {
																										new System.Data.Common.DataTableMapping("Table", "customer", new System.Data.Common.DataColumnMapping[] {
																																																					new System.Data.Common.DataColumnMapping("cust_id", "cust_id"),
																																																					new System.Data.Common.DataColumnMapping("company", "company"),
																																																					new System.Data.Common.DataColumnMapping("contact", "contact"),
																																																					new System.Data.Common.DataColumnMapping("title", "title"),
																																																					new System.Data.Common.DataColumnMapping("address", "address"),
																																																					new System.Data.Common.DataColumnMapping("city", "city"),
																																																					new System.Data.Common.DataColumnMapping("region", "region"),
																																																					new System.Data.Common.DataColumnMapping("postalcode", "postalcode"),
																																																					new System.Data.Common.DataColumnMapping("country", "country"),
																																																					new System.Data.Common.DataColumnMapping("phone", "phone"),
																																																					new System.Data.Common.DataColumnMapping("fax", "fax"),
																																																					new System.Data.Common.DataColumnMapping("maxordamt", "maxordamt")})});
			// 
			// oleDbSelectCommand1
			// 
			this.oleDbSelectCommand1.CommandText = "SELECT cust_id, company, contact, title, address, city, region, postalcode, count" +
				"ry, phone, fax, maxordamt FROM customer";
			this.oleDbSelectCommand1.Connection = this.oleDbConnection1;
			// 
			// oleDbConnection1
			// 
			this.oleDbConnection1.ConnectionString = 
                "Data Source=\"C:\\PROGRAM FILES\\MICROSOFT VISUAL FOXPRO 7\\SAMPLES\\DATA\\TESTDATA.DBC" +
				"\";Provider=\"VFPOLEDB\"";
			// 
			// dataGrid1
			// 
			this.dataGrid1.DataMember = "customer";
			this.dataGrid1.DataSource = this.custData1;
			this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
			this.dataGrid1.Location = new System.Drawing.Point(8, 8);
			this.dataGrid1.Name = "dataGrid1";
			this.dataGrid1.ReadOnly = true;
			this.dataGrid1.Size = new System.Drawing.Size(576, 320);
			this.dataGrid1.TabIndex = 0;
			this.dataGrid1.TableStyles.AddRange(new System.Windows.Forms.DataGridTableStyle[] {
																								  this.dataGridTableStyle1});
			// 
			// dataGridTableStyle1
			// 
			this.dataGridTableStyle1.DataGrid = this.dataGrid1;
			this.dataGridTableStyle1.GridColumnStyles.AddRange(new System.Windows.Forms.DataGridColumnStyle[] {
																												  this.dataGridTextBoxColumn1,
																												  this.dataGridTextBoxColumn2,
																												  this.dataGridTextBoxColumn3});
			this.dataGridTableStyle1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
			this.dataGridTableStyle1.MappingName = "customer";
			// 
			// dataGridTextBoxColumn1
			// 
			this.dataGridTextBoxColumn1.Format = "";
			this.dataGridTextBoxColumn1.FormatInfo = null;
			this.dataGridTextBoxColumn1.HeaderText = "Customer ID";
			this.dataGridTextBoxColumn1.MappingName = "cust_id";
			this.dataGridTextBoxColumn1.Width = 50;
			// 
			// dataGridTextBoxColumn2
			// 
			this.dataGridTextBoxColumn2.Format = "";
			this.dataGridTextBoxColumn2.FormatInfo = null;
			this.dataGridTextBoxColumn2.HeaderText = "Company";
			this.dataGridTextBoxColumn2.MappingName = "company";
			this.dataGridTextBoxColumn2.Width = 200;
			// 
			// dataGridTextBoxColumn3
			// 
			this.dataGridTextBoxColumn3.Format = "";
			this.dataGridTextBoxColumn3.FormatInfo = null;
			this.dataGridTextBoxColumn3.HeaderText = "Contact";
			this.dataGridTextBoxColumn3.MappingName = "contact";
			this.dataGridTextBoxColumn3.Width = 75;
			// 
			// button2
			// 
			this.button2.Location = new System.Drawing.Point(16, 344);
			this.button2.Name = "button2";
			this.button2.TabIndex = 2;
			this.button2.Text = "Col widths";
			this.button2.Click += new System.EventHandler(this.button2_Click);
			// 
			// custData1
			// 
			this.custData1.DataSetName = "custData";
			this.custData1.Locale = new System.Globalization.CultureInfo("en-US");
			// 
			// Form1
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(592, 390);
			this.Controls.Add(this.button2);
			this.Controls.Add(this.dataGrid1);
			this.Name = "Form1";
			this.Text = "Form1";
			this.Load += new System.EventHandler(this.Form1_Load);
			((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.custData1)).EndInit();
			this.ResumeLayout(false);

		}
		#endregion

		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		[STAThread]
		static void Main() 
		{
			Application.Run(new Form1());
		}

		private void button2_Click(object sender, System.EventArgs e)
		{
			foreach(DataGridColumnStyle dcs in dataGrid1.TableStyles[0].GridColumnStyles)
			{
				MessageBox.Show( String.Format (
					"Column header:{0}\nColumn source:{1}\nColumn width:{2}",
					dcs.HeaderText,dcs.MappingName,dcs.Width));
			}
		}

		private void Form1_Load(object sender, System.EventArgs e)
		{
            oleDbDataAdapter1.Fill(custData1,"customer");
		}
	}
}
Notes: This is the first time I'm trying to post designer code. Should work this way:
(Since I'm not sending other files deleted "custData" dataset in code. Also check connectionstring).
1) Create a new C# project selecting windows application
2) A form would come up
3) Right click and select view code
4) Delete all code there and paste this one
5) Click design tab and first check connection string
6) Click oldDbDataAdapter1 and "Generate dataset" giving name 'custData' (custData1 would be added
7) Click datagrid and set DataSource to custData1 (3 columns should show up)
8) Run
9) Click col widths - You should see them as 50,200,75
10) Size any column and click again- You should see new values
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform