CSDN博客

img rickjelly2004

(C#版)*控件*有横向和竖向的滚动条的DataGrid(横向支持从第几列滚动)

发表于2004/12/14 17:28:00  2995人阅读

分类: asp.net

(添加引用Microsoft.VisualBasic)
using System.ComponentModel;
using System.Collections;
using System.Web.UI;
using System.Drawing;
using System.Web;
using Microsoft.VisualBasic;
using System.Web.UI.WebControls;

namespace XYScrollDataGridcsharp{
 [DefaultProperty("Text"), ToolboxData("<{0}:XYScrollDataGridcsharp runat=server></{0}:XYScrollDataGridcsharp>")]
 public class XYScrollDataGridcsharp :System.Web.UI.WebControls.DataGrid
 {
  private Unit mScrollWidth;
  private DataModeType mDataMode;
  private int mFixedColumns;
  private ShowScrollDataMode mShowScrollDataMode;
  private Unit ymScrollWidth;

  public enum ShowScrollDataMode
  {
   XScroll,
   YScroll,
   Both,
   None,
  }
  public enum DataModeType
  {
   可変行Scroll,
   固定行Scroll,
  }


  [NotifyParentProperty(true), Browsable(false), EditorBrowsable(EditorBrowsableState.Advanced)]
  public override bool AutoGenerateColumns
  {
   get
   {
    return base.AutoGenerateColumns;
   }
   set
   {
    base.AutoGenerateColumns = false;
   }
  }
 
  [NotifyParentProperty(true)]
  public override bool AllowCustomPaging
  {
   get
   {
    return base.AllowCustomPaging;
   }
   set
   {
    base.AllowCustomPaging = value;
   }
  }

  [NotifyParentProperty(true)]
  public override bool AllowPaging
  {
   get
   {
    return base.AllowPaging;
   }
   set
   {
    base.AllowPaging = value;
   }
  }


  [NotifyParentProperty(true), Browsable(false), EditorBrowsable(EditorBrowsableState.Advanced)]
  public override bool AllowSorting
  {
   get
   {
    return base.AllowSorting;
   }
   set
   {
    base.AllowSorting = value;
   }
  }

  [NotifyParentProperty(true)]
  public override TableItemStyle AlternatingItemStyle
  {
   get
   {
    return base.AlternatingItemStyle;
   }
  }

  [NotifyParentProperty(true)]
  public override Color BackColor
  {
   get
   {
    return base.BackColor;
   }
   set
   {
    base.BackColor = value;
   }
  }

  [NotifyParentProperty(true)]
  public override string BackImageUrl
  {
   get
   {
    return base.BackImageUrl;
   }
   set
   {
    base.BackImageUrl = value;
   }
  }

  [NotifyParentProperty(true)]
  public override Color BorderColor
  {
   get
   {
    return base.BorderColor;
   }
   set
   {
    base.BorderColor = value;
   }
  }

  [NotifyParentProperty(true)]
  public override BorderStyle BorderStyle
  {
   get
   {
    return base.BorderStyle;
   }
   set
   {
    base.BorderStyle = value;
   }
  }

  [NotifyParentProperty(true)]
  public override Unit BorderWidth
  {
   get
   {
    return base.BorderWidth;
   }
   set
   {
    base.BorderWidth = value;
   }
  }

  [NotifyParentProperty(true)]
  public override int CellPadding
  {
   get
   {
    return base.CellPadding;
   }
   set
   {
    base.CellPadding = value;
   }
  }

  [NotifyParentProperty(true)]
  public override int CellSpacing
  {
   get
   {
    return base.CellSpacing;
   }
   set
   {
    base.CellSpacing = value;
   }
  }

  [NotifyParentProperty(true)]
  public override DataGridColumnCollection Columns
  {
   get
   {
    return base.Columns;
   }
  }


  [NotifyParentProperty(true)]
  public override int EditItemIndex
  {
   get
   {
    return base.EditItemIndex;
   }
   set
   {
    base.EditItemIndex = value;
   }
  }

  [NotifyParentProperty(true)]
  public override TableItemStyle EditItemStyle
  {
   get
   {
    return base.EditItemStyle;
   }
  }

  [NotifyParentProperty(true)]
  public override bool Enabled
  {
   get
   {
    return base.Enabled;
   }
   set
   {
    base.Enabled = value;
   }
  }

  [NotifyParentProperty(true)]
  public override TableItemStyle FooterStyle
  {
   get
   {
    return base.FooterStyle;
   }
  }

  [NotifyParentProperty(true)]
  public override Color ForeColor
  {
   get
   {
    return base.ForeColor;
   }
   set
   {
    base.ForeColor = value;
   }
  }

  [NotifyParentProperty(true)]
  public override GridLines GridLines
  {
   get
   {
    return base.GridLines;
   }
   set
   {
    base.GridLines = value;
   }
  }

  [NotifyParentProperty(true)]
  public override TableItemStyle HeaderStyle
  {
   get
   {
    return base.HeaderStyle;
   }
  }

  [NotifyParentProperty(true)]
  public override Unit Height
  {
   get
   {
    return base.Height;
   }
   set
   {
    base.Height = value;
   }
  }

  [NotifyParentProperty(true)]
  public override HorizontalAlign HorizontalAlign
  {
   get
   {
    return base.HorizontalAlign;
   }
   set
   {
    base.HorizontalAlign = value;
   }
  }

  [NotifyParentProperty(true)]
  public override TableItemStyle ItemStyle
  {
   get
   {
    return base.ItemStyle;
   }
  }

  [NotifyParentProperty(true)]
  public override DataGridPagerStyle PagerStyle
  {
   get
   {
    return base.PagerStyle;
   }
  }

  [NotifyParentProperty(true)]
  public override int PageSize
  {
   get
   {
    return base.PageSize;
   }
   set
   {
    base.PageSize = value;
   }
  }

  [NotifyParentProperty(true)]
  public override bool ShowFooter
  {
   get
   {
    return base.ShowFooter;
   }
   set
   {
    base.ShowFooter = value;
   }
  }

  [NotifyParentProperty(true)]
  public override bool ShowHeader
  {
   get
   {
    return base.ShowHeader;
   }
   set
   {
    base.ShowHeader = value;
   }
  }


  [NotifyParentProperty(true)]
  public override bool Visible
  {
   get
   {
    return base.Visible;
   }
   set
   {
    base.Visible = value;
   }
  }

  [NotifyParentProperty(true)]
  public override Unit Width
  {
   get
   {
    return base.Width;
   }
   set
   {
    base.Width = value;
   }
  }

  [NotifyParentProperty(true)]
  public override string CssClass
  {
   get
   {
    return base.CssClass;
   }
   set
   {
    base.CssClass = value;
   }
  }

  [Category("モード選択"), DefaultValue(typeof(Unit), "0px"), Description("スクロールの幅")]
  public Unit YScrollBarHeight
  {
   get
   {
    return ymScrollWidth;
   }
   set
   {
    ymScrollWidth = value;
   }
  }

  [Category("モード選択"), DefaultValue(typeof(Unit), "0px"), Description("スクロールの幅")]
  public Unit XScrollBarWidth
  {
   get
   {
    return mScrollWidth;
   }
   set
   {
    mScrollWidth = value;
   }
  }

  [Category("/u30e2/u30fc/u30c9/u9078/u629e"), Description("/u56fa/u5b9a/u884c/u306e/u500b/u6570"), DefaultValue(0)]
  public int FixedColumns
  {
   get
   {
   
    if (this.mShowScrollDataMode == ShowScrollDataMode.XScroll)
    {
     return this.mFixedColumns;
    }
    return 0;
   }
   set
   {
    if (this.mShowScrollDataMode != ShowScrollDataMode.XScroll)
    {
     return;
    }
    if ((this.Columns.Count < value) & (this.Columns.Count != 0))
    {
     this.mFixedColumns = this.Columns.Count;
    }
    else if (value < 0)
    {
     this.mFixedColumns = 0;
    }
    else
    {
     this.mFixedColumns = value;
    }
   }
  }


  [Category("モード選択"), DefaultValue(typeof(ShowScrollDataMode), "XScroll"), Description("XScroll")]
  public ShowScrollDataMode ShowScrollMode
  {
   get
   {
    return mShowScrollDataMode;
   }
   set
   {
    mShowScrollDataMode = value;
   }
  }

  protected override void Render(HtmlTextWriter writer)
  {
   Hashtable hashtable1 = new Hashtable();
   hashtable1.Add("Z-INDEX", this.Style["Z-INDEX"]);
   hashtable1.Add("LEFT", this.Style["LEFT"]);
   hashtable1.Add("POSITION", this.Style["POSITION"]);
   hashtable1.Add("TOP", this.Style["TOP"]);
   this.Style.Remove("Z-INDEX");
   this.Style.Remove("LEFT");
   this.Style.Remove("POSITION");
   this.Style.Remove("TOP");
   writer.Write("<div id='" + this.ID + "_All' style='");
   writer.Write("Z-INDEX: ", hashtable1["Z-INDEX"]);
   writer.Write("LEFT: ", hashtable1["LEFT"]);
   writer.Write("POSITION: ", hashtable1["POSITION"]);
   writer.Write("TOP: ", hashtable1["TOP"], "' ms_positioning = 'FlowLayout'>");
   this.FixedColumnDataGrid(writer);
   writer.Write("</div>");

  }

  private void FixedColumnDataGrid(HtmlTextWriter output)
  {
   string text2;
   string text4;
   text2="";
   text4="";
   bool[] flagArray1 = new bool[(this.Columns.Count - 1) + 1];

   int num7 = this.Columns.Count - 1;

   for (int num2 = 0; num2 <= num7; num2++)
   {
    flagArray1[num2] = this.Columns[num2].Visible;
   }
   int num1 = 0;
   int num6 = this.mFixedColumns - 1;
   for (int num3 = 0; num3 <= num6; num3++)
   {
    int num5 = this.Columns.Count - 1;
    for (int num4 = num1; num4 <= num5; num4++)
    {
     if (this.Columns[num4].Visible)
     {
      text4 = System.Convert.ToString(Conversion.Val(text4) + Conversion.Val(this.Columns[num4].HeaderStyle.Width.ToString()));
      num1 = num4 + 1;
      break;
     }
    }
   }
  
   text4 = System.Convert.ToString((Conversion.Val(text4) + 1) + (Conversion.Val(this.CellSpacing) * this.mFixedColumns));
   if (this.mFixedColumns == 0)
   {
    text4 = "0";
   }
   string text5 = this.mScrollWidth.ToString();
   string text3 = this.mScrollWidth.ToString();
   this.OutPutLayout(text4, text5, text2, text3, flagArray1, output);
  }


  private void OutPutLayout(string widthOne, string widthTwo, string heightOne, string heightTwo, bool[] visiableColumn, HtmlTextWriter output)
  {
   output.Write("<table cellSpacing='0' cellPadding='0' border='0'>");
   if (this.ShowScrollMode == ShowScrollDataMode.None)
   {
    output.Write("<tr>");
    if (this.Columns.Count > this.mFixedColumns)
    {
     this.ShowLeft("", output);
    }
    output.Write("</tr>");
   }
   else if (this.ShowScrollMode ==ShowScrollDataMode.XScroll)
   {
    output.Write("<tr>");
    this.ShowLeft(widthOne, output);
    if (this.Columns.Count > this.mFixedColumns)
    {
     this.ShowRight(widthTwo, output);
    }
    output.Write("</tr>");
   }
   else if (this.ShowScrollMode == ShowScrollDataMode.YScroll)
   {
    output.Write("<tr>");
    this.ShowTop(heightOne, output);
    output.Write("</tr>");
    if (this.Columns.Count > this.mFixedColumns)
    {
     output.Write("<tr>");
     this.ShowBottom(heightTwo, output);
     output.Write("</tr>");
    }
   }
   else if (this.ShowScrollMode == ShowScrollDataMode.Both)
   {
    output.Write("<tr>");
    this.ShowTop(heightOne, output);
    output.Write("</tr>");
    if (this.mFixedColumns == 0)
    {
     output.Write("<tr>");
     this.BothScroll(heightTwo, output);
     output.Write("</tr>");
    }
   }
   int num2 = this.Columns.Count - 1;
   for (int num1 = 0; num1 <= num2; num1++)
   {
    this.Columns[num1].Visible = visiableColumn[num1];
   }
   output.Write("</table>");
  }

  private void BothScroll(string width, HtmlTextWriter output)
  {
   output.Write("<td valign='top'>");
   string[] textArray1 = new string[6] { "<DIV id='", this.ID, "_DivBottom' style='OVERFLOW-Y: scroll; OVERFLOW-X: scroll;HEIGHT: ", this.YScrollBarHeight.ToString(), "; WIDTH: ", this.XScrollBarWidth.ToString() } ;
   string text1 = string.Concat(textArray1) + "; BORDER-TOP-STYLE: none; BORDER-RIGHT-STYLE: none; BORDER-LEFT-STYLE: none; ' ms_positioning = 'GridLayout' > ";
   output.Write(text1);
   int num4 = this.Items.Count - 1;
   for (int num1 = 0; num1 <= num4; num1++)
   {
    this.Items[num1].Visible = true;
   }
   int num3 = this.Items.Count - 1;
   for (int num2 = 0; num2 <= num3; num2++)
   {
    this.Items[num2].Attributes["id"] = this.ID + "TRD" + num2;
   }
   this.Style["BORDER-STYLE"] = "none";
   this.ShowHeader = false;
   base.Render(output);
   this.ShowHeader = true;
   output.Write("</DIV>");
   output.Write("</td>");
  }

  private void ShowBottom(string height, HtmlTextWriter output)
  {
   output.Write("<td valign='top'>");
   string text1 = ("<DIV id='" + this.ID + "_DivBottom' style='OVERFLOW-Y: scroll; HEIGHT: " + this.YScrollBarHeight.ToString()) + "; BORDER-TOP-STYLE: none; BORDER-RIGHT-STYLE: none; BORDER-LEFT-STYLE: none; ' ms_positioning = 'GridLayout' > ";
   output.Write(text1);
   int num4 = this.Items.Count - 1;
   for (int num1 = 0; num1 <= num4; num1++)
   {
    this.Items[num1].Visible = true;
   }
   int num3 = this.Items.Count - 1;
   for (int num2 = 0; num2 <= num3; num2++)
   {
    this.Items[num2].Attributes["id"] = this.ID + "TRD" + num2;
   }
   this.Style["BORDER-STYLE"] = "none";
   this.ShowHeader = false;
   base.Render(output);
   this.ShowHeader = true;
   output.Write("</DIV>");
   output.Write("</td>");
  }

  private void ShowLeft(string width, HtmlTextWriter output)
  {
   output.Write("<td valign='top'>");
   string text1 = ("<DIV id='" + this.ID + "_DivLeft' style='OVERFLOW-X: hidden; WIDTH: " + width) + "; BORDER-TOP-STYLE: none; BORDER-RIGHT-STYLE: none; BORDER-LEFT-STYLE: none; ' ms_positioning = 'GridLayout' > ";
   output.Write(text1);
   if (this.mShowScrollDataMode == ShowScrollDataMode.None)
   {
    int num4 = this.Items.Count - 1;
    for (int num1 = 0; num1 <= num4; num1++)
    {
     this.Items[num1].Attributes["id"] = this.ID + "TRD" + num1;
    }
   }
   else
   {
    int num3 = this.Items.Count - 1;
    for (int num2 = 0; num2 <= num3; num2++)
    {
     this.Items[num2].Attributes["id"] = this.ID + "TRL" + num2;
    }
   }
   this.Style["BORDER-STYLE"] = "none";
   base.Render(output);
   output.Write("</DIV>");
   output.Write("</td>");
  }

  private void ShowRight(string width, HtmlTextWriter output)
  {
   output.Write("<td valign='top'>");
   string text1 = ("<DIV id='" + this.ID + "_DivRight' style='OVERFLOW-X: scroll; WIDTH: " + width) + "; BORDER-TOP-STYLE: none; BORDER-RIGHT-STYLE: none; BORDER-LEFT-STYLE: none; ' ms_positioning = 'GridLayout' > ";
   output.Write(text1);
   if (this.ShowScrollMode != ShowScrollDataMode.None)
   {
    int num6 = this.mFixedColumns - 1;
    for (int num1 = 0; num1 <= num6; num1++)
    {
     int num5 = this.Columns.Count - 1;
     for (int num2 = 0; num2 <= num5; num2++)
     {
      if (this.Columns[num2].Visible)
      {
       this.Columns[num2].Visible = false;
       break;
      }
     }
    }
   }
   int num4 = this.Items.Count - 1;
   for (int num3 = 0; num3 <= num4; num3++)
   {
    this.Items[num3].Attributes["id"] = this.ID + "TRR" + num3;
   }
   this.Style["BORDER-STYLE"] = "none";
   base.Render(output);
   output.Write("</DIV>");
   output.Write("</td>");
  }

  private void ShowTop(string height, HtmlTextWriter output)
  {
   output.Write("<td valign='bottom' align='left'>");
   string text1 = ("<DIV id='" + this.ID) + "_DivTop' style='BORDER-TOP-STYLE: none; BORDER-RIGHT-STYLE: none; BORDER-LEFT-STYLE: none; ' ms_positioning = 'GridLayout' > ";
   output.Write(text1);
   int num4 = this.Items.Count - 1;
   for (int num1 = 0; num1 <= num4; num1++)
   {
    this.Items[num1].Visible = false;
   }
   int num3 = this.Items.Count - 1;
   for (int num2 = 0; num2 <= num3; num2++)
   {
    this.Items[num2].Attributes["id"] = this.ID + "TRD" + num2;
   }
   this.Style["BORDER-STYLE"] = "none";
   this.ShowFooter = false;
   base.Render(output);
   output.Write("</DIV>");
   output.Write("</td>");
  }
 }
}

阅读全文
0 0

相关文章推荐

img
取 消
img