Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
355 views
in Technique[技术] by (71.8m points)

c# 3.0 - how to put checkboxes in datagrid in windows mobile 6 using c#?

how to put checkboxes in datagrid in windows mobile 6 using c#?

dataset dsAgent=table; DataTable dataTable = dsAgent.Tables[0];

            DataGridTableStyle tableStyle = new DataGridTableStyle();

            tableStyle.MappingName = dataTable.TableName;

            GridColumnStylesCollection columnStyles = tableStyle.GridColumnStyles;

            DataGridTextBoxColumn columnStyle = new DataGridTextBoxColumn();
            columnStyle.MappingName = "FirstName";
            columnStyle.HeaderText = "Name";
            columnStyle.Width = 80;
            columnStyles.Add(columnStyle);

            //columnStyle = new DataGridTextBoxColumn();
            //columnStyle.MappingName = "EmailAddress";
            //columnStyle.HeaderText = "EmailID";
            //columnStyle.Width = 150;
            //columnStyles.Add(columnStyle);

            columnStyle = new DataGridTextBoxColumn();
            columnStyle.MappingName = "WorkPhone";
            columnStyle.HeaderText = "PhoneNo";
            columnStyle.Width = 150;
            columnStyles.Add(columnStyle);


            GridTableStylesCollection tableStyles = DataGrid.TableStyles;
            tableStyles.Add(tableStyle);


            DataGrid.PreferredRowHeight = 16;
            DataGrid.RowHeadersVisible = false;
            DataGrid.DataSource = dataTable;
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Here's some code from and old blog by Eric Hartwell (pulled into SO using the wayback machine):

    private void SetupTableStyles()
    {
       Color alternatingColor = SystemColors.ControlDark;
       DataTable vehicle = dataSource.Tables[1];

       // ID Column 
       DataGridCustomTextBoxColumn dataGridCustomColumn0 = new DataGridCustomTextBoxColumn();
       dataGridCustomColumn0.Owner = this.dataGrid1;
       dataGridCustomColumn0.Format = "0##";
       dataGridCustomColumn0.FormatInfo = null;
       dataGridCustomColumn0.HeaderText = vehicle.Columns[0].ColumnName;
       dataGridCustomColumn0.MappingName = vehicle.Columns[0].ColumnName;
       dataGridCustomColumn0.Width = dataGrid1.Width * 10 / 100;    // 10% of grid size
       dataGridCustomColumn0.AlternatingBackColor = alternatingColor;
       dataGridCustomColumn0.ReadOnly = true;
       dataGridTableStyle1.GridColumnStyles.Add(dataGridCustomColumn0);

       // Make column
       DataGridCustomTextBoxColumn dataGridCustomColumn1 = new DataGridCustomTextBoxColumn();
       dataGridCustomColumn1.Owner = this.dataGrid1;
       dataGridCustomColumn1.HeaderText = vehicle.Columns[1].ColumnName;
       dataGridCustomColumn1.MappingName = vehicle.Columns[1].ColumnName;
       dataGridCustomColumn1.NullText = "-Probably Ford-";
       dataGridCustomColumn1.Width = dataGrid1.Width * 40 / 100;     // 40% of grid size
       dataGridCustomColumn1.Alignment = HorizontalAlignment.Right;
       dataGridCustomColumn1.AlternatingBackColor = alternatingColor;
       dataGridTableStyle1.GridColumnStyles.Add(dataGridCustomColumn1);

       // Mileage column
       DataGridCustomUpDownColumn dataGridCustomColumn2 = new DataGridCustomUpDownColumn();
       dataGridCustomColumn2.Owner = this.dataGrid1;
       dataGridCustomColumn2.HeaderText = vehicle.Columns[2].ColumnName;
       dataGridCustomColumn2.MappingName = vehicle.Columns[2].ColumnName;
       dataGridCustomColumn2.NullText = "-Unknown-";
       dataGridCustomColumn2.Width = dataGrid1.Width * 20 / 100;     // 20% of grid size
       dataGridCustomColumn2.Alignment = HorizontalAlignment.Left;
       dataGridCustomColumn2.AlternatingBackColor = alternatingColor;
       dataGridTableStyle1.GridColumnStyles.Add(dataGridCustomColumn2);

       // Availability column 
       DataGridCustomCheckBoxColumn dataGridCustomColumn3 = new DataGridCustomCheckBoxColumn();
       dataGridCustomColumn3.Owner = this.dataGrid1;
       dataGridCustomColumn3.HeaderText = vehicle.Columns[3].ColumnName;
       dataGridCustomColumn3.MappingName = vehicle.Columns[3].ColumnName;
       dataGridCustomColumn3.NullText = "-Unknown-";
       dataGridCustomColumn3.Width = dataGrid1.Width * 10 / 100;     // 10% of grid size
       dataGridCustomColumn3.Alignment = HorizontalAlignment.Left;
       dataGridCustomColumn3.AlternatingBackColor = alternatingColor;
       dataGridTableStyle1.GridColumnStyles.Add(dataGridCustomColumn3);

       // Fuel Level column
       DataGridCustomComboBoxColumn dataGridCustomColumn4 = new DataGridCustomComboBoxColumn();
       dataGridCustomColumn4.Owner = this.dataGrid1;
       dataGridCustomColumn4.HeaderText = vehicle.Columns[4].ColumnName;
       dataGridCustomColumn4.MappingName = vehicle.Columns[4].ColumnName;
       dataGridCustomColumn4.NullText = "-Unknown-";
       dataGridCustomColumn4.Width = dataGrid1.Width * 30 / 100;     // 30% of grid size
       dataGridCustomColumn4.Alignment = HorizontalAlignment.Left;
       dataGridCustomColumn4.AlternatingBackColor = alternatingColor;
       dataGridTableStyle1.GridColumnStyles.Add(dataGridCustomColumn4);

       // Last Used column
       DataGridCustomDateTimePickerColumn dataGridCustomColumn5 = new DataGridCustomDateTimePickerColumn();
       dataGridCustomColumn5.Owner = this.dataGrid1;
       dataGridCustomColumn5.HeaderText = vehicle.Columns[5].ColumnName;
       dataGridCustomColumn5.MappingName = vehicle.Columns[5].ColumnName;
       dataGridCustomColumn5.NullText = "-Unknown-";
       dataGridCustomColumn5.Width = dataGrid1.Width * 30 / 100;     // 30% of grid size
       dataGridCustomColumn5.Alignment = HorizontalAlignment.Left;
       dataGridCustomColumn5.AlternatingBackColor = alternatingColor;
       dataGridTableStyle1.GridColumnStyles.Add(dataGridCustomColumn5);

       // Grid, mapping
       dataGridTableStyle1.MappingName = vehicle.TableName;                       // Setup table mapping name
       dataGrid1.DataSource = vehicle;                                  

       // Setup grid's data source
       ComboBox cb = (ComboBox)dataGridCustomColumn4.HostedControl;
       DataTable fuel = dataSource.Tables[0];                                                    // Set up data source
       cb.DataSource = fuel;                                            

       // For combo box column
       cb.DisplayMember = fuel.Columns[0].ColumnName;
       cb.ValueMember = fuel.Columns[0].ColumnName;

       dataGrid1.CurrentRowIndex = 50;                                                            // Move to the middle of the table
    }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...