コード例 #1
0
ファイル: kb318581.cs プロジェクト: wateras/winforms
    void Form1_Load(object sender, EventArgs e)
    {
        /* Generate sample data
         * Two columns:
         *    Decimal - uses CRTextBoxColumn for column style.
         *    Integer - uses standard DataGridTextBoxColumn for column style.
         */

        DataTable dt = new DataTable();

        dt.TableName = "TestTable";
        dt.Columns.Add("Amount", typeof(Decimal));
        dt.Columns.Add("ColB", typeof(Int32));
        ds.Tables.Add(dt);
        dt.Rows.Add(new object[] { 2, 4 });
        dt.Rows.Add(new object[] { -3.45, 5 });
        dt.Rows.Add(new object[] { 4.25, 6 });
        dt.Rows.Add(new object[] { -1.33, 7 });

        /*
         * Create DataGridTableStyle and DataGridColumnStyle objects
         * and add them the the DataGrid.
         */
        DataGridTableStyle  ts = new DataGridTableStyle();
        DataGridColumnStyle cs;

        /* Add the custom column style. */
        cs             = new CRTextBoxColumn();
        cs.Width       = 120;
        cs.MappingName = "Amount";         /* Map to decimal column. */
        cs.HeaderText  = "Charge/Payment";
        ts.GridColumnStyles.Add(cs);

        /* Add the standard column style. */
        cs             = new DataGridTextBoxColumn();
        cs.Width       = 100;
        cs.MappingName = "ColB";         /* Map to integer column. */
        cs.HeaderText  = "Integer Col";
        ts.GridColumnStyles.Add(cs);

        ts.MappingName = "TestTable";         /* Map table style to TestTable. */
        dataGrid1.TableStyles.Add(ts);

        dataGrid1.DataSource = ds;
        dataGrid1.DataMember = "TestTable";
    }
コード例 #2
0
ファイル: kb318581.cs プロジェクト: hitswa/winforms
	void Form1_Load (object sender, EventArgs e)
	{
		/* Generate sample data
		   Two columns:
		      Decimal - uses CRTextBoxColumn for column style.
		      Integer - uses standard DataGridTextBoxColumn for column style.
		*/

		DataTable dt = new DataTable ();
		dt.TableName = "TestTable";
		dt.Columns.Add ("Amount", typeof(Decimal));
		dt.Columns.Add ("ColB", typeof (Int32));
		ds.Tables.Add(dt);
		dt.Rows.Add(new object[] {2, 4});
		dt.Rows.Add(new object[] {-3.45, 5});
		dt.Rows.Add(new object[] {4.25, 6});
		dt.Rows.Add(new object[] {-1.33, 7});

		/*
		 * Create DataGridTableStyle and DataGridColumnStyle objects
		 * and add them the the DataGrid.
		 */
		DataGridTableStyle ts = new DataGridTableStyle ();
		DataGridColumnStyle cs;

		/* Add the custom column style. */
		cs = new CRTextBoxColumn();
		cs.Width = 120;
		cs.MappingName = "Amount"; /* Map to decimal column. */
		cs.HeaderText = "Charge/Payment";
		ts.GridColumnStyles.Add(cs);

		/* Add the standard column style. */
		cs = new DataGridTextBoxColumn();
		cs.Width = 100;
		cs.MappingName = "ColB"; /* Map to integer column. */
		cs.HeaderText = "Integer Col";
		ts.GridColumnStyles.Add(cs);

		ts.MappingName = "TestTable"; /* Map table style to TestTable. */
		dataGrid1.TableStyles.Add(ts);

		dataGrid1.DataSource = ds;
		dataGrid1.DataMember = "TestTable";
	}