Esempio n. 1
0
        private void frmSampleGrid1_Load(object sender, System.EventArgs e)
        {
            string[] l_CountryList = new string[] { "Italy", "France", "Spain", "UK", "Argentina", "Mexico", "Switzerland", "Brazil", "Germany", "Portugal", "Sweden", "Austria" };

            grid1.RowsCount                    = 1;
            grid1.ColumnsCount                 = 10;
            grid1.FixedRows                    = 1;
            grid1.FixedColumns                 = 1;
            grid1.Selection.SelectionMode      = SourceGrid.GridSelectionMode.Row;
            grid1.AutoStretchColumnsToFitWidth = true;
            grid1.Columns[0].AutoSizeMode      = SourceGrid.AutoSizeMode.None;
            grid1.Columns[0].Width             = 25;

            //Enable Drag and Drop
            grid1.GridController.AddController(SourceGrid.Controllers.SelectionDrag.Cut);
            grid1.GridController.AddController(SourceGrid.Controllers.SelectionDrop.Default);


            #region Create Grid Style, Views and Controllers
            //Views
            mView_Default = new SourceGrid.Cells.Views.Cell();

            mView_Price = new SourceGrid.Cells.Views.Cell();
            mView_Price.TextAlignment = DevAge.Drawing.ContentAlignment.MiddleRight;

            mView_CheckBox = new SourceGrid.Cells.Views.CheckBox();

            mView_Link = new SourceGrid.Cells.Views.Link();

            mView_RowHeader    = new SourceGrid.Cells.Views.RowHeader();
            mView_ColumnHeader = new SourceGrid.Cells.Views.ColumnHeader();
            mView_Header       = new SourceGrid.Cells.Views.Header();

            //Style
            SourceGrid.Styles.StyleGrid style = new SourceGrid.Styles.StyleGrid();
            style.StyleCells.Add(new SourceGrid.Styles.StyleCell(null, null, typeof(string), mView_Default));
            style.StyleCells.Add(new SourceGrid.Styles.StyleCell(null, null, typeof(DateTime), mView_Default));
            style.StyleCells.Add(new SourceGrid.Styles.StyleCell(null, null, typeof(int), mView_Default));
            style.StyleCells.Add(new SourceGrid.Styles.StyleCell(null, null, typeof(Boolean), mView_CheckBox));
            style.StyleCells.Add(new SourceGrid.Styles.StyleCell(null, null, typeof(double), mView_Price));
            style.StyleCells.Add(new SourceGrid.Styles.StyleCell(typeof(SourceGrid.Cells.Link), null, null, mView_Link));
            style.StyleCells.Add(new SourceGrid.Styles.StyleCell(typeof(SourceGrid.Cells.Header), null, null, mView_Header));
            style.StyleCells.Add(new SourceGrid.Styles.StyleCell(typeof(SourceGrid.Cells.ColumnHeader), null, null, mView_ColumnHeader));
            style.StyleCells.Add(new SourceGrid.Styles.StyleCell(typeof(SourceGrid.Cells.RowHeader), null, null, mView_RowHeader));
            grid1.StyleGrid = style;

            mController_Link           = new SourceGrid.Cells.Controllers.Button();
            mController_Link.Executed += new EventHandler(mController_Link_Click);
            #endregion

            #region Create Header Row and Editor
            SourceGrid.Cells.Header l_00Header = new SourceGrid.Cells.Header(null);
            grid1[0, 0] = l_00Header;

            mEditor_Id = SourceGrid.Cells.Editors.Factory.Create(typeof(int));
            mEditor_Id.EditableMode = SourceGrid.EditableMode.Focus | SourceGrid.EditableMode.AnyKey | SourceGrid.EditableMode.SingleClick;
            grid1[0, 1]             = new SourceGrid.Cells.ColumnHeader("ID (int)");

            mEditor_Name = SourceGrid.Cells.Editors.Factory.Create(typeof(string));
            mEditor_Name.EditableMode = SourceGrid.EditableMode.Focus | SourceGrid.EditableMode.AnyKey | SourceGrid.EditableMode.SingleClick;
            grid1[0, 2] = new SourceGrid.Cells.ColumnHeader("NAME (string)");

            mEditor_Address = SourceGrid.Cells.Editors.Factory.Create(typeof(string));
            mEditor_Address.EditableMode = SourceGrid.EditableMode.Focus | SourceGrid.EditableMode.AnyKey | SourceGrid.EditableMode.SingleClick;
            grid1[0, 3] = new SourceGrid.Cells.ColumnHeader("ADDRESS (string)");

            mEditor_City = SourceGrid.Cells.Editors.Factory.Create(typeof(string));
            mEditor_City.EditableMode = SourceGrid.EditableMode.Focus | SourceGrid.EditableMode.AnyKey | SourceGrid.EditableMode.SingleClick;
            grid1[0, 4] = new SourceGrid.Cells.ColumnHeader("CITY (string)");

            mEditor_BirthDay = SourceGrid.Cells.Editors.Factory.Create(typeof(DateTime));
            mEditor_BirthDay.EditableMode = SourceGrid.EditableMode.Focus | SourceGrid.EditableMode.AnyKey | SourceGrid.EditableMode.SingleClick;
            grid1[0, 5] = new SourceGrid.Cells.ColumnHeader("BIRTHDATE (DateTime)");

            mEditor_Country = new SourceGrid.Cells.Editors.ComboBox(typeof(string), l_CountryList, false);
            mEditor_Country.EditableMode = SourceGrid.EditableMode.Focus | SourceGrid.EditableMode.AnyKey | SourceGrid.EditableMode.SingleClick;
            grid1[0, 6] = new SourceGrid.Cells.ColumnHeader("COUNTRY (string + combobox)");

            mEditor_Price = new SourceGrid.Cells.Editors.TextBoxCurrency(typeof(double));
            mEditor_Price.EditableMode = SourceGrid.EditableMode.Focus | SourceGrid.EditableMode.AnyKey | SourceGrid.EditableMode.SingleClick;
            grid1[0, 7] = new SourceGrid.Cells.ColumnHeader("$ PRICE (double)");

            grid1[0, 8] = new SourceGrid.Cells.ColumnHeader("Selected");

            grid1[0, 9] = new SourceGrid.Cells.ColumnHeader("WebSite");
            #endregion

            //Read Data From xml
            System.IO.StreamReader reader = new System.IO.StreamReader(System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("WindowsFormsSample.GridSamples.SampleData.xml"));
            System.Xml.XmlDocument xmlDoc = new System.Xml.XmlDocument();
            xmlDoc.LoadXml(reader.ReadToEnd());
            reader.Close();
            System.Xml.XmlNodeList rows = xmlDoc.SelectNodes("//row");
            grid1.RowsCount = rows.Count + 1;
            int rowsCount = 1;
            foreach (System.Xml.XmlNode l_Node in rows)
            {
                #region Pupulate RowsCount
                grid1[rowsCount, 0] = new SourceGrid.Cells.RowHeader(null);

                grid1[rowsCount, 1] = new SourceGrid.Cells.Cell(rowsCount, mEditor_Id);

                grid1[rowsCount, 2] = new SourceGrid.Cells.Cell(l_Node.Attributes["ContactName"].InnerText, mEditor_Name);

                grid1[rowsCount, 3] = new SourceGrid.Cells.Cell(l_Node.Attributes["Address"].InnerText, mEditor_Address);

                grid1[rowsCount, 4] = new SourceGrid.Cells.Cell(l_Node.Attributes["City"].InnerText, mEditor_City);

                grid1[rowsCount, 5] = new SourceGrid.Cells.Cell(DateTime.Today, mEditor_BirthDay);

                grid1[rowsCount, 6] = new SourceGrid.Cells.Cell(l_Node.Attributes["Country"].InnerText, mEditor_Country);

                grid1[rowsCount, 7] = new SourceGrid.Cells.Cell(25.0, mEditor_Price);

                grid1[rowsCount, 8] = new SourceGrid.Cells.CheckBox(null, false);

                grid1[rowsCount, 9] = new SourceGrid.Cells.Link(l_Node.Attributes["website"].InnerText);
                grid1[rowsCount, 9].AddController(mController_Link);
                #endregion

                rowsCount++;
            }

            grid1.AutoSizeCells();
        }
Esempio n. 2
0
        private void InitializeGrid()
        {
            if (m_IsInitialized)
            {
                return;
            }

            // 設定 grid 預設的欄寬與列高
            brGrid.DefaultWidth  = 30;
            brGrid.DefaultHeight = 20;

            // 設定 grid 列數與行數。
            int maxCol = m_BrDoc.CellsPerLine;              // brDoc.LongestLine.Words.Count;

            brGrid.Redim(m_BrDoc.Lines.Count * 3 + FixedRows, maxCol + FixedColumns);

            // 設定欄寬最小限制,以免呼叫 AutoSizeView 時,欄寬被縮得太小。
            for (int i = 1; i < brGrid.ColumnsCount; i++)
            {
                brGrid.Columns[i].MinimalWidth = 24;
            }
            brGrid.Columns[0].MinimalWidth = 40;                // 第 0 欄要顯示列號,需要寬些.

            // 標題欄
            if (m_HeaderView == null)
            {
                m_HeaderView      = new SourceGrid.Cells.Views.Header();
                m_HeaderView.Font = new Font(brGrid.Font, FontStyle.Regular);
            }

            if (m_HeaderView2 == null)
            {
                m_HeaderView2 = new SourceGrid.Cells.Views.RowHeader();
                DevAge.Drawing.VisualElements.RowHeader backHeader = new DevAge.Drawing.VisualElements.RowHeader();
                backHeader.BackColor     = Color.Blue;
                m_HeaderView2.Background = backHeader;
                m_HeaderView2.Font       = m_HeaderView.Font;
            }

            CreateFixedArea();

            // Font objects

            if (m_PhonFont == null)
            {
                m_PhonFont = new Font("PMingLiU", DualEditForm.DefaultPhoneticFontSize, FontStyle.Regular, GraphicsUnit.Point, 1);
            }

            if (m_MingFont == null)
            {
                m_MingFont = new Font("Arial Unicode MS", DualEditForm.DefaultTextFontSize, FontStyle.Regular, GraphicsUnit.Point, 0);
                // Note: 原本為新細明體,可是為了顯示英文音標等特殊符號,必須使用 Arial Unicode MS 字型。
            }
            if (m_MingFontCJK == null)
            {
                m_MingFontCJK = new Font("PMingLiU", DualEditForm.DefaultTextFontSize, FontStyle.Regular, GraphicsUnit.Point, 1);
            }

            // view for 點字
            if (m_BrView == null)
            {
                m_BrView              = new SourceGrid.Cells.Views.Cell();
                m_BrView.BackColor    = Color.Snow;
                m_BrView.Font         = new Font("SimBraille", DualEditForm.DefaultBrailleFontSize);
                m_BrView.TrimmingMode = SourceGrid.TrimmingMode.None;
            }

            // view for 明眼字
            if (m_MingView == null)
            {
                m_MingView                  = new SourceGrid.Cells.Views.Cell();
                m_MingView.BackColor        = Color.Snow;
                m_MingView.Font             = m_MingFont;
                m_MingView.ElementText.Font = m_MingFont;
            }

            if (m_MingViewCJK == null)
            {
                m_MingViewCJK                  = new SourceGrid.Cells.Views.Cell();
                m_MingViewCJK.BackColor        = Color.Snow;
                m_MingViewCJK.Font             = m_MingFontCJK;
                m_MingViewCJK.ElementText.Font = m_MingFontCJK;
            }

            // view for 注音符號
            if (m_PhonView == null)
            {
                m_PhonView              = new SourceGrid.Cells.Views.Cell();
                m_PhonView.BackColor    = Color.YellowGreen;
                m_PhonView.Font         = m_PhonFont;
                m_PhonView.TrimmingMode = SourceGrid.TrimmingMode.None;
            }

            // view for 破音字的注音符號
            if (m_PhonView2 == null)
            {
                m_PhonView2              = new SourceGrid.Cells.Views.Cell();
                m_PhonView2.BackColor    = Color.Yellow;
                m_PhonView2.Font         = m_PhonFont;
                m_PhonView2.TrimmingMode = SourceGrid.TrimmingMode.None;
            }
            // view for 容易判斷錯誤的破音字注音符號
            if (m_PhonView3 == null)
            {
                m_PhonView3              = new SourceGrid.Cells.Views.Cell();
                m_PhonView3.BackColor    = Color.Red;
                m_PhonView3.Font         = m_PhonFont;
                m_PhonView3.TrimmingMode = SourceGrid.TrimmingMode.None;
            }

            // 設置 controllers
            if (m_MenuController == null)
            {
                m_MenuController = new PopupMenuController();
                m_MenuController.PopupMenuClick += new SourceGrid.CellContextEventHandler(GridMenu_Click);
            }

            if (m_ClickController == null)
            {
                m_ClickController = new CellClickEvent(this);
            }

            m_IsInitialized = true;
        }