示例#1
0
        private void makeDataGridTableStyle()
        {
            this.dataGridTableStyle = new DataGridTableStyle();

            this.dataGridTableStyle.DataGrid        = this.favoritesDataGrid;
            this.dataGridTableStyle.HeaderForeColor = System.Drawing.SystemColors.ControlText;
            this.dataGridTableStyle.MappingName     = "favoritesTable";

            //
            // nameDataGridTextBoxColumn
            //
            DataGridTextBoxColumn nameDataGridTextBoxColumn = new DataGridTextBoxColumn();

            nameDataGridTextBoxColumn.Format      = "";
            nameDataGridTextBoxColumn.FormatInfo  = null;
            nameDataGridTextBoxColumn.HeaderText  = "Name";
            nameDataGridTextBoxColumn.MappingName = "name";
            nameDataGridTextBoxColumn.NullText    = "";
            nameDataGridTextBoxColumn.Width       = 200;
            this.dataGridTableStyle.GridColumnStyles.Add(nameDataGridTextBoxColumn);
            //
            // locationDataGridTextBoxColumn
            //
            DataGridTextBoxColumn locationDataGridTextBoxColumn = new DataGridTextBoxColumn();

            locationDataGridTextBoxColumn.Format      = "";
            locationDataGridTextBoxColumn.FormatInfo  = null;
            locationDataGridTextBoxColumn.HeaderText  = "Location / Camera Altitude";
            locationDataGridTextBoxColumn.MappingName = "location";
            locationDataGridTextBoxColumn.NullText    = "";
            locationDataGridTextBoxColumn.Width       = 350;
            this.dataGridTableStyle.GridColumnStyles.Add(locationDataGridTextBoxColumn);

            // Create an int column style and add it to the tablestyle
            // this requires setting the format for the column through its property descriptor
            PropertyDescriptorCollection pdc = this.BindingContext[favoritesDataSet, "favoritesTable"].GetItemProperties();
            //now created a formated column using the pdc
            DataGridDigitsTextBoxColumn csIDInt = new DataGridDigitsTextBoxColumn(pdc["id"], "i", true);

            csIDInt.MappingName = "id";
            csIDInt.HeaderText  = "";
            csIDInt.Width       = 1;
            dataGridTableStyle.GridColumnStyles.Add(csIDInt);

            /*
             * //
             * // latDataGridTextBoxColumn
             * //
             * DataGridTextBoxColumn latDataGridTextBoxColumn = new DataGridTextBoxColumn();
             * latDataGridTextBoxColumn.Format = "";
             * latDataGridTextBoxColumn.FormatInfo = null;
             * latDataGridTextBoxColumn.HeaderText = "Latitude";
             * latDataGridTextBoxColumn.MappingName = "lat";
             * latDataGridTextBoxColumn.NullText = "";
             * latDataGridTextBoxColumn.Width = 75;
             * this.dataGridTableStyle.GridColumnStyles.Add(latDataGridTextBoxColumn);
             * //
             * // lngDataGridTextBoxColumn
             * //
             * DataGridTextBoxColumn lngDataGridTextBoxColumn = new DataGridTextBoxColumn();
             * lngDataGridTextBoxColumn.Format = "";
             * lngDataGridTextBoxColumn.FormatInfo = null;
             * lngDataGridTextBoxColumn.HeaderText = "Longitude";
             * lngDataGridTextBoxColumn.MappingName = "lng";
             * lngDataGridTextBoxColumn.NullText = "";
             * lngDataGridTextBoxColumn.Width = 75;
             * this.dataGridTableStyle.GridColumnStyles.Add(lngDataGridTextBoxColumn);
             * //
             * // elevDataGridTextBoxColumn
             * //
             * DataGridTextBoxColumn elevDataGridTextBoxColumn = new DataGridTextBoxColumn();
             * elevDataGridTextBoxColumn.Alignment = System.Windows.Forms.HorizontalAlignment.Right;
             * elevDataGridTextBoxColumn.Format = "";
             * elevDataGridTextBoxColumn.FormatInfo = null;
             * elevDataGridTextBoxColumn.HeaderText = "Camera Altitude";
             * elevDataGridTextBoxColumn.MappingName = "elev";
             * elevDataGridTextBoxColumn.NullText = "";
             * elevDataGridTextBoxColumn.Width = 120;
             * this.dataGridTableStyle.GridColumnStyles.Add(elevDataGridTextBoxColumn);
             */

            favoritesDataGrid.CaptionVisible = false;
        }
示例#2
0
        private void makeGeotiffDataGridStyle()
        {
            if (m_geotiffTS != null)
            {
                return;
            }

            //STEP 1: Create a DataTable style object and set properties if required.
            m_geotiffTS = new DataGridTableStyle();
            //specify the table from dataset (required step)
            m_geotiffTS.MappingName = "geotiff";
            // Set other properties (optional step)
            //m_geotiffTS.AlternatingBackColor = Color.LightBlue;

            int colCount = 0;

            //STEP 1: Create an int column style and add it to the tablestyle
            //this requires setting the format for the column through its property descriptor
            PropertyDescriptorCollection pdc = this.BindingContext[m_geotiffDS, "geotiff"].GetItemProperties();
            //now created a formated column using the pdc
            DataGridDigitsTextBoxColumn csIDInt = new DataGridDigitsTextBoxColumn(pdc["id"], "i", true);

            csIDInt.MappingName = "id";
            csIDInt.HeaderText  = "";
            csIDInt.Width       = 30;
            csIDInt.ReadOnly    = true;
            m_geotiffTS.GridColumnStyles.Add(csIDInt);
            colCount++;

            //STEP 2: Create a string column and add it to the tablestyle
            NameCol             = new DataGridTextBoxColumn();
            NameCol.MappingName = "name";             //from dataset table
            NameCol.HeaderText  = "Name";
            NameCol.Width       = Math.Max(10, Project.nameColWidthCm);
            NameCol.ReadOnly    = true;
            m_geotiffTS.GridColumnStyles.Add(NameCol);
            colCount++;

            //STEP 3: Add the checkbox
            DataGridColumnStyle boolCol = new MyDataGridBoolColumn(colCount);

            boolCol.MappingName = "displayed";
            boolCol.HeaderText  = "Shown";
            //hook the new event to our handler in the grid
            ((MyDataGridBoolColumn)boolCol).BoolValueChanged += new BoolValueChangedEventHandler(HandleCustomMapShowChanges);
            //uncomment this line to get a two-state checkbox
            ((DataGridBoolColumn)boolCol).AllowNull = false;
            boolCol.Width = 45;
            m_geotiffTS.GridColumnStyles.Add(boolCol);
            colCount++;

            //STEP 3: Add the checkbox
            DataGridColumnStyle boolCol2 = new MyDataGridBoolColumn(colCount);

            boolCol2.MappingName = "persist";
            boolCol2.HeaderText  = "Load on start";
            //hook the new event to our handler in the grid
            ((MyDataGridBoolColumn)boolCol2).BoolValueChanged += new BoolValueChangedEventHandler(HandleCustomMapPersistChanges);
            //uncomment this line to get a two-state checkbox
            ((DataGridBoolColumn)boolCol2).AllowNull = false;
            boolCol2.Width = 80;
            m_geotiffTS.GridColumnStyles.Add(boolCol2);
            colCount++;

            //STEP 4: Create a string column and add it to the tablestyle
            DescrCol             = new DataGridTextBoxColumn();
            DescrCol.MappingName = "descr";             //from dataset table
            DescrCol.HeaderText  = "Description";
            //DescrCol.Width = Math.Max(10, Project.descColWidthCm);
            DescrCol.Width    = 1;
            DescrCol.ReadOnly = true;
            m_geotiffTS.GridColumnStyles.Add(DescrCol);
            colCount++;

            //STEP 5: Create a string column and add it to the tablestyle
            SourceCol             = new DataGridTextBoxColumn();
            SourceCol.MappingName = "source";             //from dataset table
            SourceCol.HeaderText  = "Source";
            int colWidthLeft = Math.Max(100, this.Width - csIDInt.Width - NameCol.Width - boolCol.Width - DescrCol.Width - 140);

            SourceCol.Width    = Math.Max(colWidthLeft, 100);          // Project.sourceColWidthCm);
            SourceCol.ReadOnly = true;
            m_geotiffTS.GridColumnStyles.Add(SourceCol);
            colCount++;

            geotiffDataGrid.CaptionVisible = false;

            //STEP 6: Add the tablestyle to your datagrid's tablestlye collection:
            geotiffDataGrid.TableStyles.Add(m_geotiffTS);

            /* how to test for checked checkboxes:
             * if((bool)geotiffDataGrid[row, column])
             *      MessageBox.Show("I am true");
             * else
             *      MessageBox.Show("I am false");
             */
        }