Пример #1
0
        private void InitializeDGV(DataGridView DGV)
        {
            // Create an unbound DataGridView by declaring a column count.
            DGV.ColumnCount          = 4;
            DGV.ColumnHeadersVisible = true;

            // Set the column header style.
            DataGridViewCellStyle columnHeaderStyle = new DataGridViewCellStyle();

            columnHeaderStyle.BackColor       = Color.Beige;
            columnHeaderStyle.Font            = new Font("Verdana", 10, FontStyle.Bold);
            DGV.ColumnHeadersDefaultCellStyle = columnHeaderStyle;

            // Resize the height of the column headers.
            DGV.AutoResizeColumnHeadersHeight();
            // Resize all the row heights to fit the contents of all non-header cells.
            DGV.AutoResizeRows(
                DataGridViewAutoSizeRowsMode.AllCellsExceptHeaders);

            // Set the column header names.
            DGV.Columns[0].Name     = "序号";
            DGV.Columns[1].Name     = "列名";
            DGV.Columns[2].Name     = "线颜色";
            DGV.Columns[3].Name     = "变量";
            DGV.Columns[0].Width    = 50;
            DGV.Columns[1].Width    = 300;
            DGV.Columns[2].Width    = 80;
            DGV.Columns[3].Width    = 150;
            DGV.Columns[0].ReadOnly = true;
            DGV.Columns[2].ReadOnly = true;
            DGV.Columns[3].ReadOnly = true;
        }
Пример #2
0
        /// <summary>
        /// create a table of orders
        /// создать таблицу ордеров
        /// </summary>
        private DataGridView CreateOrderTable()
        {
            DataGridView newGrid = DataGridFactory.GetDataGridOrder();

            newGrid.AutoResizeColumnHeadersHeight();
            return(newGrid);
        }
Пример #3
0
    //<snippet3>
    private void button1_Click(object sender, System.EventArgs e)
    {
        // Resize the height of the column headers.
        dataGridView1.AutoResizeColumnHeadersHeight();

        // Resize all the row heights to fit the contents of all non-header cells.
        dataGridView1.AutoResizeRows(
            DataGridViewAutoSizeRowsMode.AllCellsExceptHeaders);
    }
Пример #4
0
        private DataGridView CreateOrderTable()
        {
            DataGridView newGrid = DataGridFactory.GetDataGridOrder(false);

            newGrid.ScrollBars    = ScrollBars.Vertical;
            newGrid.SelectionMode = DataGridViewSelectionMode.CellSelect;
            newGrid.AutoResizeColumnHeadersHeight();
            return(newGrid);
        }
Пример #5
0
 private static void SetDgvDefaults(DataGridView dgv)
 {
     dgv.AllowUserToAddRows    = false;
     dgv.AllowUserToDeleteRows = false;
     dgv.AutoGenerateColumns   = false;
     dgv.AutoResizeColumnHeadersHeight( );
     dgv.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.None;
     dgv.AutoSizeRowsMode    = DataGridViewAutoSizeRowsMode.None;
     dgv.MultiSelect         = true;
     dgv.ReadOnly            = true;
     dgv.RowHeadersVisible   = true;
 }
Пример #6
0
        /// ------------------------------------------------------------------------------------
        public void InitializeGrid(DataGridView grid)
        {
            foreach (var col in Columns)
            {
                if (!grid.Columns.Contains(col.Id))
                {
                    continue;
                }

                grid.Columns[col.Id].Visible = col.Visible;

                if (col.Width >= 0 &&
                    (grid.Columns[col.Id].AutoSizeMode == DataGridViewAutoSizeColumnMode.None ||
                     grid.Columns[col.Id].AutoSizeMode == DataGridViewAutoSizeColumnMode.NotSet))
                {
                    grid.Columns[col.Id].Width = col.Width;
                }
                else if (col.FillWeight > 0 && grid.Columns[col.Id].AutoSizeMode == DataGridViewAutoSizeColumnMode.Fill)
                {
                    grid.Columns[col.Id].FillWeight = col.FillWeight;
                }

                if (col.DisplayIndex < 0)
                {
                    grid.Columns[col.Id].DisplayIndex = 0;
                }
                else if (col.DisplayIndex >= grid.ColumnCount)
                {
                    grid.Columns[col.Id].DisplayIndex = grid.ColumnCount - 1;
                }
                else
                {
                    grid.Columns[col.Id].DisplayIndex = col.DisplayIndex;
                }
            }

            // If the column header height or the former dpi settings are different,
            // then auto. calculate the height of the column headings.
            if (ColumnHeaderHeight <= 0 || DPI != m_currDpi)
            {
                grid.AutoResizeColumnHeadersHeight();
            }
            else
            {
                grid.ColumnHeadersHeight = ColumnHeaderHeight;
            }
        }
Пример #7
0
        /// ------------------------------------------------------------------------------------
        public void InitializeGrid(DataGridView grid)
        {
            foreach (var col in Columns)
            {
                if (!grid.Columns.Contains(col.Id))
                {
                    continue;
                }

                grid.Columns[col.Id].Visible = col.Visible;

                if (col.Width >= 0)
                {
                    grid.Columns[col.Id].Width = col.Width;
                }

                if (col.DisplayIndex < 0)
                {
                    grid.Columns[col.Id].DisplayIndex = 0;
                }
                else if (col.DisplayIndex >= grid.ColumnCount)
                {
                    grid.Columns[col.Id].DisplayIndex = grid.ColumnCount - 1;
                }
                else
                {
                    grid.Columns[col.Id].DisplayIndex = col.DisplayIndex;
                }
            }

            if (!grid.VirtualMode && !string.IsNullOrEmpty(SortedColumn) && grid.Columns.Contains(SortedColumn))
            {
                grid.Sort(grid.Columns[SortedColumn], SortOrder == SortOrder.Descending ? ListSortDirection.Descending : ListSortDirection.Ascending);
            }

            // If the column header height or the former dpi settings are different,
            // then auto. calculate the height of the column headings.
            if (ColumnHeaderHeight <= 0 || DPI != m_currDpi)
            {
                grid.AutoResizeColumnHeadersHeight();
            }
            else
            {
                grid.ColumnHeadersHeight = ColumnHeaderHeight;
            }
        }
Пример #8
0
        public void DGV_SetStyle(DataGridView Dgv)
        {
            Dgv.RowsDefaultCellStyle.BackColor            = Color.NavajoWhite;
            Dgv.AlternatingRowsDefaultCellStyle.BackColor = Properties.Settings.Default.dgvColor;
            Dgv.DefaultCellStyle.WrapMode = DataGridViewTriState.True;
            Dgv.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
            Dgv.AutoResizeColumnHeadersHeight();

            //Dgv.AutoResizeColumns();
            foreach (DataGridViewColumn col in Dgv.Columns)
            {
                col.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
            }
            Dgv.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells;
            Dgv.Refresh();
            Dgv.Invalidate();
        }
Пример #9
0
        private void PopulateDataGridView()
        {
            // Setup data to be populated
            string[] row0 = { "11/22/1968", "29", "Revolution 9",
                              "Beatles",    "The Beatles [White Album]" };
            string[] row1 = { "1960",          "6", "Fools Rush In",
                              "Frank Sinatra", "Nice 'N' Easy" };
            string[] row2 = { "11/11/1971", "1", "One of These Days",
                              "Pink Floyd", "Meddle" };
            string[] row3 = { "1988",   "7", "Where Is My Mind?",
                              "Pixies", "Surfer Rosa" };
            string[] row4 = { "5/1981", "9", "Can't Find My Mind",
                              "Cramps", "Psychedelic Jungle" };
            string[] row5 = { "6/10/2003",                          "13",
                              "Scatterbrain. (As Dead As Leaves.)",
                              "Radiohead",                          "Hail to the Thief" };
            string[] row6 = { "6/30/1992", "3", "Dress", "P J Harvey", "Dry" };
            object[] rows = new object[] { row1, row2, row3, row4, row5 };


            // Add rows of data to DataGridView
            foreach (string[] rowArray in rows)
            {
                dataGridView1.Rows.Add(rowArray);
            }

            // Set display order of columns
            dataGridView1.Columns[0].DisplayIndex = 3;
            dataGridView1.Columns[1].DisplayIndex = 4;
            dataGridView1.Columns[2].DisplayIndex = 0;
            dataGridView1.Columns[3].DisplayIndex = 1;
            dataGridView1.Columns[4].DisplayIndex = 2;

            // Resize the columns to fit the newly loaded data.
            dataGridView1.AutoResizeColumns();

            // Resize the height of the column headers.
            dataGridView1.AutoResizeColumnHeadersHeight();

            // Resize all the row heights to fit the contents of all non-header cells.
            dataGridView1.AutoResizeRows(DataGridViewAutoSizeRowsMode.AllCellsExceptHeaders);
        }
 private void UpdateScoreBoard()
 {
     scoreBoardTable.ColumnCount = 3 + games.Count;
     for (int c = 0; c < scoreBoardTable.ColumnCount; c++)
     {
         var col = scoreBoardTable.Columns[c];
         if (c == 0)
         {
             col.Name         = "Rank";
             col.HeaderText   = "";
             col.AutoSizeMode = DataGridViewAutoSizeColumnMode.None;
             col.Width        = 48;
         }
         else if (c == 1)
         {
             col.Name       = "Player";
             col.HeaderText = "Player";
             col.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft;
         }
         else if (c == scoreBoardTable.ColumnCount - 1)
         {
             col.Name       = "Totals";
             col.HeaderText = "Totals";
             col.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
             //col.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
         }
         else
         {
             var game = games[c - 2];
             col.Name       = "Game_" + game.ID;
             col.HeaderText = game.Name;
             col.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
             //col.AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells;
         }
     }
     scoreBoardTable.RowCount = players.Count;
     scoreBoardTable.AutoResizeColumnHeadersHeight();
     scoreBoardTable.Invalidate();
 }
Пример #11
0
        private void InitDGV(DataGridView dgv, int iCol, int iRow, List <string> sList, List <string> sRow)
        {
            // Create an unbound DataGridView by declaring a column count.
            dgv.ColumnCount          = iCol;
            dgv.RowCount             = iRow;
            dgv.ColumnHeadersVisible = true;

            // Set the column header style.
            DataGridViewCellStyle columnHeaderStyle = new DataGridViewCellStyle();

            columnHeaderStyle.BackColor       = Color.Beige;
            columnHeaderStyle.Font            = new Font("Verdana", 10, FontStyle.Bold);
            dgv.ColumnHeadersDefaultCellStyle = columnHeaderStyle;

            // Resize the height of the column headers.
            dgv.AutoResizeColumnHeadersHeight();
            // Resize all the row heights to fit the contents of all non-header cells.
            dgv.AutoResizeRows(
                DataGridViewAutoSizeRowsMode.AllCellsExceptHeaders);

            // Set the column header names.
            for (int i = 0; i < iCol; i++)
            {
                dgv.Columns[i].Name = sList[i];
            }

            for (int i = 0; i < iRow; i++)
            {
                string   str1 = sRow[i];
                string[] str2 = str1.Split(',');
                for (int j = 0; j < iCol; j++)
                {
                    dgv.Rows[i].Cells[j].Value = str2[j];
                }
            }
            dgv.AutoResizeColumns();
        }
Пример #12
0
        // Populate grid with user and application settings
        private void PopulateDataGridView()
        {
            List <string[]> list;

            list = GetSettings();

            foreach (string[] array in list)
            {
                dataGridView1.Rows.Add(array);
            }

            // Make cell with connection string readonly
            dataGridView1[1, 0].ReadOnly = true;

            // Resize the columns to fit the newly loaded data.
            // Use this method if AutoSizeColumnsMode property is not set.
            //dataGridView1.AutoResizeColumns();

            // Resize the height of the column headers
            dataGridView1.AutoResizeColumnHeadersHeight();

            // Resize all the row heights to fit the contents of all non-header cells
            dataGridView1.AutoResizeRows(DataGridViewAutoSizeRowsMode.AllCellsExceptHeaders);
        }
Пример #13
0
 public void UpdateGrid(DataTable bsource)
 {
     dbDataGridView.DataSource = bsource;
     dbDataGridView.AutoResizeColumnHeadersHeight();
 }
Пример #14
0
        public void LoadProfile(Person p)
        {
            nameLabel.Text = p.FullName;

            //load interviews
            bool isCandidate   = p.IsCandidate();
            bool isInterviewer = p.IsInterviewer();

            if (isCandidate)
            {
                Candidate candidate = p.GetCandidate();
                //differentiate if user has multiple types of interviews
                if (isInterviewer)
                {
                    Label newLabel = new Label();
                    newLabel.AutoSize = true;
                    newLabel.Text     = "Candidate: ";
                    //size is determined by text
                    //location is determined below by vertically arranging contents of interviewPanel
                    interviewPanel.Controls.Add(newLabel);
                }

                DataGridView grid = new DataGridView();

                grid.ColumnCount     = 3;
                grid.Columns[0].Name = "Company";
                grid.Columns[1].Name = "Table";
                grid.Columns[2].Name = "Time";

                String statement = "SELECT Companies.Name, Interviews.TableID, TimeSlots.StartTime FROM Interviews, InterviewInterviewers, Interviewers, CompanyInterviewers, Companies, TimeSlots " +
                                   "WHERE Interviews.CandidateID = " + candidate.ID + " " +
                                   "AND Interviews.ID = InterviewInterviewers.InterviewID AND InterviewInterviewers.InterviewerID = Interviewers.ID AND Interviewers.ID = CompanyInterviewers.InterviewerID AND CompanyInterviewers.CompanyID = Companies.ID " +
                                   "AND Interviews.TimeSlotID = TimeSlots.ID";

                SqlConnection connection = new SqlConnection(MySQLUtils.ConnectionString);
                connection.Open();

                SqlCommand command = new SqlCommand(statement, connection);

                SqlDataReader reader = command.ExecuteReader();

                while (reader.Read())
                {
                    String[] row = new String[] {
                        reader.GetString(reader.GetOrdinal("Name")),
                        "" + reader.GetInt32(reader.GetOrdinal("TableID")),
                        "" + reader.GetTimeSpan(reader.GetOrdinal("StartTime")),
                    };
                    grid.Rows.Add(row);
                }
                connection.Close();

                interviewPanel.Controls.Add(grid);

                //have to resize after adding because the font size is set ny the container
                grid.AutoResizeColumnHeadersHeight();
            }
            if (isInterviewer)
            {
                Interviewer interviewer = p.GetInterviewer();
                //differentiate if user has multiple types of interviews
                if (isCandidate)
                {
                    Label newLabel = new Label();
                    newLabel.AutoSize = true;
                    newLabel.Text     = "Interviewer: ";
                    //size is determined by text
                    //location is determined below by vertically arranging contents of interviewPanel
                    interviewPanel.Controls.Add(newLabel);
                }

                DataGridView grid = new DataGridView();
                grid.ColumnCount     = 3;
                grid.Columns[0].Name = "Candidate";
                grid.Columns[1].Name = "Table";
                grid.Columns[2].Name = "Time";

                String statement = "SELECT People.First, Interviews.TableID, TimeSlots.StartTime FROM Interviews, InterviewInterviewers, Interviewers, Candidates, People, TimeSlots " +
                                   "WHERE Interviewers.ID = " + interviewer.ID + " " +
                                   "AND Interviews.ID = InterviewInterviewers.InterviewID AND InterviewInterviewers.InterviewerID = Interviewers.ID " +
                                   "AND Interviews.CandidateID = Candidates.ID AND Candidates.PersonID = People.ID " +
                                   "AND Interviews.TimeSlotID = TimeSlots.ID";

                SqlConnection connection = new SqlConnection(MySQLUtils.ConnectionString);
                connection.Open();

                SqlCommand command = new SqlCommand(statement, connection);

                SqlDataReader reader = command.ExecuteReader();

                while (reader.Read())
                {
                    String[] row = new String[] {
                        reader.GetString(reader.GetOrdinal("First")),
                        "" + reader.GetInt32(reader.GetOrdinal("TableID")),
                        "" + reader.GetTimeSpan(reader.GetOrdinal("StartTime")),
                    };
                    grid.Rows.Add(row);
                }
                connection.Close();

                interviewPanel.Controls.Add(grid);

                //have to resize after adding because the font size is set ny the container
                grid.AutoResizeColumnHeadersHeight();
            }

            VerticallyArrangeContents(interviewPanel);
        }
Пример #15
0
    //</snippet1>

    //<snippet2>
    private void SizeColumnHeaders(Object sender, EventArgs e)
    {
        dataGridView1.AutoResizeColumnHeadersHeight(2);
    }
Пример #16
0
 void TattleMain_MouseEnter(object sender, EventArgs e)
 {
     dg.AutoResizeColumnHeadersHeight();
 }
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Assigns properties to the specified grid.
        /// </summary>
        /// <param name="grid">Grid for whose settings are being loaded</param>
        /// <param name="gridLinesValue">string value corresponding to the type of grid
        /// lines read from the settings file for the specified grid</param>
        /// <returns>True on success</returns>
        /// ------------------------------------------------------------------------------------
        public bool LoadGridProperties(DataGridView grid, out string gridLinesValue)
        {
            gridLinesValue = null;

            if (m_xmlDoc == null || grid == null)
            {
                return(false);
            }

            XmlNode node = FindChildNode(kGridsNode, grid.Name);

            if (node == null)
            {
                return(false);
            }

            // Get the cell border style.
            gridLinesValue = XmlHelper.GetAttributeValue(node, "lines");

            // Get the column header height and dpi setting
            // when the grid's settings were last saved.
            int    colHdrHeight = XmlHelper.GetIntFromAttribute(node, "colheaderheight", -1);
            string sdpi         = XmlHelper.GetAttributeValue(node, "dpi");
            float  dpi;

            if (!float.TryParse(sdpi, out dpi))
            {
                dpi = 0;
            }

            // Get each column's properties.
            node = node.FirstChild;
            while (node != null)
            {
                if (node.NodeType != XmlNodeType.Comment)
                {
                    try
                    {
                        string id = XmlHelper.GetAttributeValue(node, "id");
                        grid.Columns[id].Visible = XmlHelper.GetBoolFromAttribute(node, "visible", true);

                        int width = XmlHelper.GetIntFromAttribute(node, "width", -1);
                        if (width > -1)
                        {
                            grid.Columns[id].Width = width;
                        }

                        int displayIndex = XmlHelper.GetIntFromAttribute(node, "displayindex", -1);
                        if (displayIndex > -1)
                        {
                            grid.Columns[id].DisplayIndex = displayIndex;
                        }
                    }
                    catch { }
                }

                node = node.NextSibling;
            }

            // If the column header height or the former dpi settings are different,
            // then auto. calculate the height of the column headings.
            if (colHdrHeight == -1 || dpi != m_currSystemDpi)
            {
                grid.AutoResizeColumnHeadersHeight();
            }
            else
            {
                grid.ColumnHeadersHeight = colHdrHeight;
            }

            return(dpi == m_currSystemDpi);
        }
Пример #18
0
        private void PopulateDataGridView()
        {
            // Use list to populate DataGridView
            List <string[]> list = new List <string[]>();

            string connectionString = "Data Source=sample.sqlite;Version=3;";

            using (SQLiteConnection connection = new SQLiteConnection(connectionString))
            {
                connection.Open();

                using (SQLiteCommand command = new SQLiteCommand(connection))
                {
                    string sql = "SELECT * FROM Log ORDER BY strftime('%Y-%m-%d %H:%M:%f', timestamp) DESC";
                    command.CommandText = sql;
                    using (SQLiteDataReader reader = command.ExecuteReader())
                    {
                        // Get data from database and add rows to list
                        while (reader.Read())
                        {
                            string[] row = new string[3];
                            row[0] = reader["timestamp"].ToString();
                            row[1] = reader["temp1"].ToString();
                            row[2] = reader["temp2"].ToString();
                            list.Add(row);
                        }
                    }
                }

                connection.Close();
            }

            // Create datatable
            DataTable table = new DataTable();

            table.Columns.Add("TIMESTAMP", typeof(string));
            table.Columns.Add("TEMP1", typeof(int));
            table.Columns.Add("TEMP2", typeof(double));

            // Add rows of data to DataTable
            foreach (string[] row in list)
            {
                table.Rows.Add(row);
            }

            // Bind DataTable to DataGridView
            dataGridView1.DataSource = table;

            dataGridView1.Columns[0].ReadOnly = true;
            dataGridView1.Columns[1].ReadOnly = true;
            dataGridView1.Columns[2].ReadOnly = true;

            // Set display order of columns
            dataGridView1.Columns[0].DisplayIndex = 0;
            dataGridView1.Columns[1].DisplayIndex = 1;
            dataGridView1.Columns[2].DisplayIndex = 2;

            // Resize the columns to fit the newly loaded data.
            dataGridView1.AutoResizeColumns();

            // Resize the height of the column headers.
            dataGridView1.AutoResizeColumnHeadersHeight();

            // Resize all the row heights to fit the contents of all non-header cells.
            dataGridView1.AutoResizeRows(DataGridViewAutoSizeRowsMode.AllCellsExceptHeaders);
        }