Ejemplo n.º 1
0
        protected virtual void BindGrid <T>(List <T> source, PageabledEventArgs args)
        {
            //这种控件绑定有些耗性能,可能换dataGrid控件,dataGrid.DataSoucre 绑定性能高很多
            gridColumns.Clear();
            superGrid.PrimaryGrid.Columns.Clear();
            superGrid.PrimaryGrid.Rows.Clear();
            if (bindGridColumns != null && bindGridColumns.Count > 0)
            {
                foreach (var column in bindGridColumns)
                {
                    GridColumn gColumn = new GridColumn()
                    {
                        Name             = column.PropertieName,
                        HeaderText       = column.HeaderText,
                        DataPropertyName = column.PropertieName,
                        DataType         = column.PropertieType
                    };
                    gridColumns.Add(gColumn);
                    superGrid.PrimaryGrid.Columns.Add(gColumn);
                }


                if (source != null && source.Count > 0)
                {
                    T   t          = source.FirstOrDefault <T>();
                    var properties = t.GetType().GetProperties().ToList();
                    foreach (var item in source)
                    {
                        GridRow dr = superGrid.PrimaryGrid.NewRow();
                        for (int i = 0; i < gridColumns.Count; i++)
                        {
                            GridColumn gColumn = gridColumns[i];
                            var        value   = properties.FirstOrDefault(x => x.Name.Equals(gColumn.Name)).GetValue(item);
                            //处理bool 是与否
                            if (gColumn.DataType.Equals(typeof(bool)))
                            {
                                if (Convert.ToBoolean(value))
                                {
                                    dr[gColumn].Value = "是";
                                }
                                else
                                {
                                    dr[gColumn].Value = "否";
                                }
                            }
                            else if (gColumn.DataType.IsEnum)
                            {
                                dr[gColumn].Value = EnumHelper.GetDescription(gColumn.DataType, value.ToString());
                            }
                            else
                            {
                                dr[gColumn].Value = value;
                            }
                        }

                        superGrid.PrimaryGrid.Rows.Add(dr);
                    }
                }

                //控制表格只能选中单行
                superGrid.PrimaryGrid.MultiSelect      = true;
                superGrid.PrimaryGrid.InitialSelection = RelativeSelection.Row;
                //只能选中一个单元格,而不是一行单元格
                superGrid.PrimaryGrid.SelectionGranularity = SelectionGranularity.Row;

                superGrid.PrimaryGrid.ShowRowHeaders       = true;
                superGrid.PrimaryGrid.ShowRowGridIndex     = true;
                superGrid.PrimaryGrid.RowHeaderIndexOffset = 1;

                superGrid.PrimaryGrid.Filter.Visible        = true;
                superGrid.PrimaryGrid.EnableFiltering       = true;
                superGrid.PrimaryGrid.EnableColumnFiltering = true;

                superGrid.PrimaryGrid.ColumnAutoSizeMode = ColumnAutoSizeMode.AllCells;

                superGrid.PrimaryGrid.ColumnHeader.AllowSelection = true;
                superGrid.PrimaryGrid.GroupByRow.Visible          = false;

                GridPanel panel = superGrid.PrimaryGrid;
                panel.AutoExpandSetGroup = true;
                superGrid.PrimaryGrid.DefaultVisualStyles.CellStyles.Default.Alignment = DevComponents.DotNetBar.SuperGrid.Style.Alignment.MiddleCenter;
                this.pageToolBar.ChangePageCount(args.TotalCount);
            }
        }
Ejemplo n.º 2
0
 private void PageToolBarCmbPageSizeSelectedIndexChanged(object sender, PageabledEventArgs arg)
 {
     BindGrid <object>(null, arg);
 }
Ejemplo n.º 3
0
 private void SearchClick(object sender, PageabledEventArgs arg)
 {
     BindGrid <object>(null, arg);
 }
Ejemplo n.º 4
0
 private void PageToolBar_NextClick(object sender, PageabledEventArgs arg)
 {
     BindGrid <object>(null, arg);
 }
Ejemplo n.º 5
0
 protected virtual void DeleteClick(object sender, PageabledEventArgs e)
 {
 }