惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Recent Announcements
Recent Announcements
人人都是产品经理
人人都是产品经理
月光博客
月光博客
博客园 - 三生石上(FineUI控件)
GbyAI
GbyAI
博客园 - 司徒正美
美团技术团队
Vercel News
Vercel News
IT之家
IT之家
U
Unit 42
Y
Y Combinator Blog
罗磊的独立博客
Microsoft Security Blog
Microsoft Security Blog
MongoDB | Blog
MongoDB | Blog
Jina AI
Jina AI
V
Visual Studio Blog
B
Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
MyScale Blog
MyScale Blog
博客园 - 叶小钗
A
About on SuperTechFans
WordPress大学
WordPress大学
Hugging Face - Blog
Hugging Face - Blog
B
Blog RSS Feed

博客园 - Leo.Zhu

访问google的方法 Postgresql 迁移随笔一 英语词根6 英语词根3 英语词根4 英语词根2 英语词根 1 压力测试工具(Apache) “诸葛马前课-小六壬”全面解析 QT 中中文问题 - Leo.Zhu - 博客园 Ubuntu 尝试 C# 开发Activex ListView + ToolTip 的問題 JQueuy 使用记录---FileTree - Leo.Zhu - 博客园 Signals and Slots MS Ajax 客户端编程 学习笔记 (3) MS Ajax 客户端编程 学习笔记 (2) MS Ajax 客户端编程 学习笔记 (1) Englive.cn 英语 学习 在线背单词 - 语句本
dataGrid 使用记录 - Leo.Zhu - 博客园
Leo.Zhu · 2009-07-28 · via 博客园 - Leo.Zhu

DataGrid绑定Dataset,设定cell控件。

设定隐藏的栏位:

设定DataSet的Table对应的栏位为Hidden,绑定后DataGrid上不显示该栏位:

Depds.Tables["DepartMent1"].Columns["Pkey"].ColumnMapping = MappingType.Hidden;

设定DataGrid的样式:

               DataGridTableStyle dgdtblStyle = new DataGridTableStyle();
               dgdtblStyle.MappingName = this.Depds.Tables["XX"].TableName;
               if (dataGrid1.TableStyles.Contains("XX"))
                   dataGrid1.TableStyles.RemoveAt(0);

添加样式
               dataGrid1.TableStyles.Add(dgdtblStyle);
               dgdtblStyle.RowHeadersVisible = false;
               //dgdtblStyle.HeaderBackColor = Color.LightSteelBlue;           
               dgdtblStyle.AllowSorting = false;
               //dgdtblStyle.HeaderBackColor = Color.FromArgb(8,36,107);
               // dgdtblStyle.HeaderBackColor = Color.DarkGray;
               dgdtblStyle.RowHeadersVisible = true;
               dgdtblStyle.HeaderForeColor = Color.Black;

设定字体:
               dgdtblStyle.HeaderFont = new System.Drawing.Font("Microsoft Sans Serif", 9F,
               System.Drawing.FontStyle.Bold,
               System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
               //dgdtblStyle.GridLineColor = Color.DarkGray;

设定显示的高度:
               dgdtblStyle.PreferredRowHeight = 20;
               //dataGrid1.BackgroundColor = Color.White;               
               GridColumnStylesCollection colStyle = dataGrid1.TableStyles[0].GridColumnStyles;

设定显示的栏位名称:
                   colStyle[0].HeaderText = "a";
                   colStyle[1].HeaderText = "b";
                   colStyle[2].HeaderText = "c";
                   colStyle[3].HeaderText = "d";
                   colStyle[4].HeaderText = "e";
                   colStyle[5].HeaderText = "f";

//设置其下的dropbox  CreateDropBox会创建一个DropBox控件。
                DataGridTextBoxColumn f1 = (DataGridTextBoxColumn)dataGrid1.TableStyles[0].GridColumnStyles[1];
                f1.TextBox.Controls.Add(CreateDropBox());
                DataGridTextBoxColumn f2 = (DataGridTextBoxColumn)dataGrid1.TableStyles[0].GridColumnStyles[2];
                f2.TextBox.Controls.Add(CreateDropBox());
                DataGridTextBoxColumn f3 = (DataGridTextBoxColumn)dataGrid1.TableStyles[0].GridColumnStyles[3];
                f3.TextBox.Controls.Add(CreateDropBox());
                DataGridTextBoxColumn f4 = (DataGridTextBoxColumn)dataGrid1.TableStyles[0].GridColumnStyles[4];
                f4.TextBox.Controls.Add(CreateDropBox());
                DataGridTextBoxColumn f5 = (DataGridTextBoxColumn)dataGrid1.TableStyles[0].GridColumnStyles[5];
                f5.Format = "yyyy/MM/dd HH:ss:mm";

public ComboBox CreateDropBox()
      {
          try
          {
              ComboBox cmbFunctionArea = new ComboBox();

              cmbFunctionArea.Items.AddRange(Floorlist.ToArray());
              cmbFunctionArea.Cursor = Cursors.Arrow;
              cmbFunctionArea.DropDownStyle = ComboBoxStyle.DropDownList;
              cmbFunctionArea.Dock = DockStyle.Fill;
              cmbFunctionArea.SelectedIndex = 0;
              cmbFunctionArea.SelectionChangeCommitted += new EventHandler(cmbFunctionArea_SelectionChangeCommitted);
              return cmbFunctionArea;
          }
          catch (System.Exception exp)
          {
          }
          return null;
      }

收…………