Пример #1
0
        public static void InitializeDataGridView(DataGridView v, 
            int colCount, int rowCount, 
            int columnWidth = 48, int rowHeadersWidth = 64,
            string tableName = "", string colName = "", string rowName = "", 
            bool nocolNum = false, bool noRowNum = false,
            bool invertCol = false, bool invertRow = false)
        {
            v.Rows.Clear();
            // Create an unbound DataGridView by declaring a column count.
            v.ColumnCount = colCount;
            v.ColumnHeadersVisible = true;

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

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

            string[] row = new string[colCount];
            // Set the column header names.
            //int c = 1;
            for (int i = 0; i < colCount; ++i)
            {
                string name = colName;
                if (!nocolNum)
                {
                    if (invertCol)
                    {
                        name += " " + (colCount - i).ToString();
                    }
                    else
                    {
                        name += " " + (i + 1).ToString();
                    }
                }
                v.Columns[i].Name = name;
                v.Columns[i].Width = columnWidth;
            }
            v.RowHeadersWidth = rowHeadersWidth;
            v.TopLeftHeaderCell.Value = tableName;
            for (int i = 0; i < rowCount; i++)
            {
                v.Rows.Add(row);
                string name = rowName;
                if (!noRowNum)
                {
                    if (invertRow)
                    {
                        name += " " + (rowCount - i).ToString();
                    }
                    else
                    {
                        name += " " + (i + 1).ToString();
                    }
                }
                v.Rows[i].HeaderCell.Value = name;
            }
            v.PerformLayout();
        }
Пример #2
0
        public void LoadDatatoTableWithoutBindWithLable(DataGridView ObgTbl, String CmdStr, String FnName, Label _Progress)
        {
            ObgTbl.PerformLayout();
            DataTable mytb = new DataTable();
            mytb = GetDataTable(CmdStr, FnName);
            if (mytb != null)
            {
                if (mytb.Rows.Count > 0)
                {
                    Int32 NofColoums = mytb.Columns.Count;
                    String[] ParamCollection = new String[NofColoums];
                    ObgTbl.Rows.Clear();
                    for (int i = 0; i < mytb.Rows.Count; i++)
                    {
                        Application.DoEvents();
                        _Progress.Text = mytb.Rows[i][0].ToString();
                        for (int x = 0; x < NofColoums; x++)
                        {
                            string MCX = mytb.Columns[x].DataType.ToString();
                            if (MCX != "System.DateTime")

                                ParamCollection[x] = mytb.Rows[i].ItemArray.GetValue(x).ToString();
                            else
                            {
                                DateTime Xdate;
                                if (string.IsNullOrEmpty(mytb.Rows[i].ItemArray.GetValue(x).ToString()) == false)
                                    Xdate = DateTime.Parse(mytb.Rows[i].ItemArray.GetValue(x).ToString());
                                else
                                    Xdate = DateTime.MinValue;
                                ParamCollection[x] = Xdate.ToString("dd/MMM/yyyy");
                            }
                        }
                        try
                        {
                            ObgTbl.Rows.Add(ParamCollection);

                        }
                        catch (Exception ex)
                        {


                        }
                    }
                    DocolourThisGrid(ObgTbl);
                }
            }
            else
            {
                ObgTbl.Rows.Clear();
            }
        }