资源简介

在winform项目中,使用Devexpress GridControl控件,可能会遇到需要冻结头部几行的需求,本项目实例可以帮到你。

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraVerticalGrid.Rows;
using DevExpress.XtraEditors.Repository;
using DevExpress.XtraGrid.Views.Grid;
using DevExpress.XtraGrid.Views.base;
using System.Reflection;
using DevExpress.Data;

namespace WindowsApplication134 {
    public partial class Form1 : Form {
        public Form1() {
            InitializeComponent();
        }

        private void Form1_Load(object sender EventArgs e) {
            //this.order_DetailsTableAdapter.Fill(this.nwindDataSet.Order_Details);
            this.oldTopRowIndex = gridView1.TopRowIndex;

            this.gridView1.OptionsView.RowAutoHeight = false;
            //this.gridView1.OptionsView.ShowHorzLines = false;
            //this.gridView1.OptionsView.ShowVertLines = false;
            //this.gridView1.OptionsView.ColumnAutoWidth = false;
            this.gridView1.OptionsView.ShowColumnHeaders = false;
            this.gridView1.OptionsView.ShowGroupPanel = false;
            this.gridView1.OptionsView.ShowIndicator = false;
            this.gridView1.OptionsBehavior.Editable = false;
            this.gridView1.OptionsSelection.EnableAppearanceFocusedRow = false;
            this.gridView1.OptionsSelection.EnableAppearanceFocusedCell = false;
        }

        const int FixedRowCount = 1;

        private void gridView1_CustomDrawCell(object sender DevExpress.XtraGrid.Views.base.RowCellCustomDrawEventArgs e) {
            GridView view = sender as GridView;
            if(e.RowHandle < 0) return;
            Color foreColorForFixedCells = Color.Red;
            int visibleIndex = view.GetVisibleIndex(e.RowHandle) - view.TopRowIndex;
            if(visibleIndex >= 0 && visibleIndex < FixedRowCount) {
                //if(e.Column.SummaryItem.SummaryType != SummaryItemType.None)
                {
                    string displayText = e.Column.Name.ToString() + visibleIndex.ToString();
                    //displayText  += “: “ + e.Column.SummaryItem.SummaryValue.ToString();
                    e.Graphics.DrawString(displayText e.Appearance.Font new SolidBrush(foreColorForFixedCells) e.Bounds);
                }
                e.Handled = true;
            }
        }
        int oldTopRowIndex = 0;
        private void gridView1_TopRowChanged(object sender EventArgs e) {
              GridView view = sender as GridView;
              int max = oldTopRowIndex > view.TopRowIndex ? oldTopRowIndex + FixedRowCount : view.TopRowIndex + FixedRowCount;
              for(int i = view.TopRowIndex; i < max +1; i++)
                  view.RefreshRow(i);
        }

        bool IsFixedRow(int rowHandle GridView view) {
            if(rowHandle >= view.TopRowIndex && rowHandle < view.TopRowIndex + FixedRowCount)
                return true;
            return false

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件        387  2008-02-25 02:25  FixedRows\app.config

     文件      37376  2012-09-24 11:02  FixedRows\bin\Debug\FixedRows.exe

     文件        387  2008-02-25 02:25  FixedRows\bin\Debug\FixedRows.exe.config

     文件      69120  2012-09-24 11:02  FixedRows\bin\Debug\FixedRows.pdb

     文件      11608  2012-09-24 11:02  FixedRows\bin\Debug\FixedRows.vshost.exe

     文件        387  2008-02-25 02:25  FixedRows\bin\Debug\FixedRows.vshost.exe.config

     文件        931  2011-12-08 20:52  FixedRows\FixedRows.sln

    ..A..H.     26112  2012-09-24 11:02  FixedRows\FixedRows.suo

     文件       4084  2012-09-24 11:02  FixedRows\Form1.cs

     文件       6530  2012-09-24 10:53  FixedRows\Form1.Designer.cs

     文件       6442  2012-09-24 10:53  FixedRows\Form1.resx

     文件      69434  2011-12-08 20:52  FixedRows\nwindDataSet.Designer.cs

     文件          3  2008-02-25 02:25  FixedRows\nwindDataSet.xsc

     文件      16000  2008-02-25 02:25  FixedRows\nwindDataSet.xsd

     文件          3  2008-02-25 02:25  FixedRows\nwindDataSet.xss

     文件          0  2012-09-24 10:36  FixedRows\obj\Debug\build.force

     文件      66840  2012-09-24 10:51  FixedRows\obj\Debug\DesignTimeResolveAssemblyReferences.cache

     文件       6356  2012-09-24 11:02  FixedRows\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache

     文件      37376  2012-09-24 11:02  FixedRows\obj\Debug\FixedRows.exe

     文件      69120  2012-09-24 11:02  FixedRows\obj\Debug\FixedRows.pdb

     文件        180  2012-09-24 10:52  FixedRows\obj\Debug\FixedRows.Properties.Resources.resources

     文件        406  2012-09-24 10:54  FixedRows\obj\Debug\GenerateResource-ResGen.read.1.tlog

     文件        610  2012-09-24 10:54  FixedRows\obj\Debug\GenerateResource-ResGen.write.1.tlog

     文件      28672  2012-09-24 10:33  FixedRows\obj\Debug\TempPE\nwindDataSet.Designer.cs.dll

     文件       5120  2012-09-24 10:33  FixedRows\obj\Debug\TempPE\Properties.Resources.Designer.cs.dll

     文件       1787  2012-09-24 11:02  FixedRows\obj\Debug\WindowsApplication134.csproj.FileListAbsolute.txt

     文件        180  2012-09-24 10:54  FixedRows\obj\Debug\WindowsApplication134.Form1.resources

     文件        473  2008-02-25 01:31  FixedRows\Program.cs

     文件       1292  2008-02-25 01:31  FixedRows\Properties\AssemblyInfo.cs

     文件        245  2012-09-24 11:02  FixedRows\Properties\licenses.licx

............此处省略25个文件信息

评论

共有 条评论