Exemplo n.º 1
0
        private void DataColumnDialog_Load(object sender, System.EventArgs e)
        {
            if (m_DataTable == null)
            {
                throw new ApplicationException("DataTable is null");
            }

            if (m_TemplateColumns == null)
            {
                m_TemplateColumns = GridDataTable.GetColumnsFromDataTable(m_DataTable, true);
            }

            grid.Redim(m_DataTable.Columns.Count + 1, 3);
            grid.FixedRows = 1;
            grid.Selection.SelectionMode = SourceGrid2.GridSelectionMode.Row;

            grid[0, 0] = new Cells.Header("Visible");
            grid[0, 1] = new Cells.Header("Caption");
            grid[0, 2] = new Cells.Header("Order");

            int l_LastPosition = m_TemplateColumns.Length + 1;

            for (int c = 0; c < m_DataTable.Columns.Count; c++)
            {
                int  l_CurrentPosition = l_LastPosition;
                bool l_bVisible        = false;
                for (int j = 0; j < m_TemplateColumns.Length; j++)
                {
                    if (m_TemplateColumns[j].DataColumn == m_DataTable.Columns[c])
                    {
                        l_bVisible        = true;
                        l_CurrentPosition = j + 1;
                        break;
                    }
                }
                if (l_bVisible == false)
                {
                    l_LastPosition++;
                }
                grid[c + grid.FixedRows, 0]     = new Cells.CheckBox(l_bVisible);
                grid[c + grid.FixedRows, 0].Tag = m_DataTable.Columns[c];
                grid[c + grid.FixedRows, 1]     = new Cells.Cell(m_DataTable.Columns[c].Caption, typeof(string));
                grid[c + grid.FixedRows, 1].DataModel.AllowNull = false;
                grid[c + grid.FixedRows, 2] = new Cells.Cell(l_CurrentPosition);
            }

            Sort();

            grid.AutoStretchColumnsToFitWidth = true;
            grid.AutoSizeAll();
        }
Exemplo n.º 2
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      = SourceGrid2.GridSelectionMode.Row;
            grid1.AutoStretchColumnsToFitWidth = true;
            grid1.Columns[0].AutoSizeMode      = SourceGrid2.AutoSizeMode.None;
            grid1.Columns[0].Width             = 30;

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

            m_CellEditor_Id = SourceGrid2.Utility.CreateDataModel(typeof(int));
            m_CellEditor_Id.EditableMode = SourceGrid2.EditableMode.Focus | SourceGrid2.EditableMode.AnyKey | SourceGrid2.EditableMode.SingleClick;
            grid1[0, 1] = new Cells.ColumnHeader("ID (int)");

            m_CellEditor_Name = SourceGrid2.Utility.CreateDataModel(typeof(string));
            m_CellEditor_Name.EditableMode = SourceGrid2.EditableMode.Focus | SourceGrid2.EditableMode.AnyKey | SourceGrid2.EditableMode.SingleClick;
            grid1[0, 2] = new Cells.ColumnHeader("NAME (string)");

            m_CellEditor_Address = SourceGrid2.Utility.CreateDataModel(typeof(string));
            m_CellEditor_Address.EditableMode = SourceGrid2.EditableMode.Focus | SourceGrid2.EditableMode.AnyKey | SourceGrid2.EditableMode.SingleClick;
            grid1[0, 3] = new Cells.ColumnHeader("ADDRESS (string)");

            m_CellEditor_City = SourceGrid2.Utility.CreateDataModel(typeof(string));
            m_CellEditor_City.EditableMode = SourceGrid2.EditableMode.Focus | SourceGrid2.EditableMode.AnyKey | SourceGrid2.EditableMode.SingleClick;
            grid1[0, 4] = new Cells.ColumnHeader("CITY (string)");

            m_CellEditor_BirthDay = SourceGrid2.Utility.CreateDataModel(typeof(DateTime));
            m_CellEditor_BirthDay.EditableMode = SourceGrid2.EditableMode.Focus | SourceGrid2.EditableMode.AnyKey | SourceGrid2.EditableMode.SingleClick;
            grid1[0, 5] = new Cells.ColumnHeader("BIRTHDATE (DateTime)");

            m_CellEditor_Country = new SourceGrid2.DataModels.EditorComboBox(typeof(string), l_CountryList, false);
            m_CellEditor_Country.EditableMode = SourceGrid2.EditableMode.Focus | SourceGrid2.EditableMode.AnyKey | SourceGrid2.EditableMode.SingleClick;
            grid1[0, 6] = new Cells.ColumnHeader("COUNTRY (string + combobox)");

            m_CellEditor_Price = new SourceGrid2.DataModels.EditorTextBox(typeof(double));
            m_CellEditor_Price.TypeConverter = new SourceLibrary.ComponentModel.Converter.CurrencyTypeConverter(typeof(double));
            m_CellEditor_Price.EditableMode  = SourceGrid2.EditableMode.Focus | SourceGrid2.EditableMode.AnyKey | SourceGrid2.EditableMode.SingleClick;
            grid1[0, 7] = new Cells.ColumnHeader("$ PRICE (double)");

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

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


            #region Visual Properties
            //set Cells style
            m_VisualProperties = new SourceGrid2.VisualModels.Common(false);

            m_VisualPropertiesPrice = (SourceGrid2.VisualModels.Common)m_VisualProperties.Clone(false);
            m_VisualPropertiesPrice.TextAlignment = ContentAlignment.MiddleRight;

            m_VisualPropertiesCheckBox = (SourceGrid2.VisualModels.CheckBox)SourceGrid2.VisualModels.CheckBox.Default.Clone(false);

            m_VisualPropertiesLink = (SourceGrid2.VisualModels.Common)SourceGrid2.VisualModels.Common.LinkStyle.Clone(false);
            #endregion

            //read xml
            System.IO.StreamReader l_Reader = new System.IO.StreamReader(System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("SampleProject.Samples.SampleData.xml"));
            System.Xml.XmlDocument l_XmlDoc = new System.Xml.XmlDocument();
            l_XmlDoc.LoadXml(l_Reader.ReadToEnd());
            l_Reader.Close();
            System.Xml.XmlNodeList l_Rows = l_XmlDoc.SelectNodes("//row");
            grid1.RowsCount = l_Rows.Count + 1;
            int l_RowsCount = 1;
            foreach (System.Xml.XmlNode l_Node in l_Rows)
            {
                #region Pupulate RowsCount
                grid1[l_RowsCount, 0] = new Cells.RowHeader();

                grid1[l_RowsCount, 1]             = new Cells.Cell(l_RowsCount);
                grid1[l_RowsCount, 1].DataModel   = m_CellEditor_Id;
                grid1[l_RowsCount, 1].VisualModel = m_VisualProperties;

                grid1[l_RowsCount, 2]             = new Cells.Cell(l_Node.Attributes["ContactName"].InnerText);
                grid1[l_RowsCount, 2].DataModel   = m_CellEditor_Name;
                grid1[l_RowsCount, 2].VisualModel = m_VisualProperties;

                grid1[l_RowsCount, 3]             = new Cells.Cell(l_Node.Attributes["Address"].InnerText);
                grid1[l_RowsCount, 3].DataModel   = m_CellEditor_Address;
                grid1[l_RowsCount, 3].VisualModel = m_VisualProperties;

                grid1[l_RowsCount, 4]             = new Cells.Cell(l_Node.Attributes["City"].InnerText);
                grid1[l_RowsCount, 4].DataModel   = m_CellEditor_City;
                grid1[l_RowsCount, 4].VisualModel = m_VisualProperties;

                grid1[l_RowsCount, 5]             = new Cells.Cell(DateTime.Today);
                grid1[l_RowsCount, 5].DataModel   = m_CellEditor_BirthDay;
                grid1[l_RowsCount, 5].VisualModel = m_VisualProperties;

                grid1[l_RowsCount, 6]             = new Cells.Cell(l_Node.Attributes["Country"].InnerText);
                grid1[l_RowsCount, 6].DataModel   = m_CellEditor_Country;
                grid1[l_RowsCount, 6].VisualModel = m_VisualProperties;

                grid1[l_RowsCount, 7]             = new Cells.Cell(25.0);
                grid1[l_RowsCount, 7].DataModel   = m_CellEditor_Price;
                grid1[l_RowsCount, 7].VisualModel = m_VisualPropertiesPrice;

                grid1[l_RowsCount, 8]             = new Cells.CheckBox(false);
                grid1[l_RowsCount, 8].VisualModel = m_VisualPropertiesCheckBox;

                grid1[l_RowsCount, 9]                      = new Cells.Link(l_Node.Attributes["website"].InnerText);
                grid1[l_RowsCount, 9].VisualModel          = m_VisualPropertiesLink;
                ((Cells.Link)grid1[l_RowsCount, 9]).Click += new SourceGrid2.PositionEventHandler(CellLink_Click);
                #endregion

                l_RowsCount++;
            }

            grid1.AutoSizeAll();
        }