Hide DataGrid DataSource is DataTable in the DataColumn (Visual C #)

2010-05-13  来源:本站原创  分类:DotNet  人气:237 

Code: Hidden in the DataGrid's DataSource to DataTable DataColumn (Visual C #)

This example hidden in existing Windows Forms DataGrid control to display the DataTable object "X" column.

Example

Copy

private void HideColumnOfDataSet()
{
    System.Data.DataTable points = new System.Data.DataTable("Points");
    points.Columns.Add(new DataColumn("X", typeof(int)));
    points.Columns.Add(new DataColumn("Y", typeof(int)));
    points.Rows.Add(new object[]{1, 2});
    points.Rows.Add(new object[]{3, 5});
    dataGrid1.DataSource = points;

    DataGridTableStyle tableStyle = new DataGridTableStyle();
    tableStyle.MappingName = "Points";
    dataGrid1.TableStyles.Add(tableStyle);
    dataGrid1.TableStyles["Points"].GridColumnStyles["X"].Width = 0;
}

Compiled code

This example requires:

  • With the DataGrid control named dataGrid1 Windows Forms.

If the data source is a DataSet object, it will set the DataGrid's DataMember property to the name of the table.

Typed dataset DataTable and DataColumn objects also has a string type name. To find the name of the table, see Table Name attribute. To find the DataColumn names, check out the Name property.

Reliable Programming

The following conditions may cause an exception:

  • MappingName property and DataTable ( NullReferenceException Class ) do not match the name.
  • In the TableStyle to DataGrid.TableStyles set before the start GridColumnStyles retrieve a particular set. In the TableStyle object to the TableStyles collection ( NullReferenceException Class ) in, they will fill GridColumnStyles collection.
  • Add to the DataGrid. TableStyles collection TableStyle not the only MappingName ( ArgumentException class ).
  • Visit GridColumnStyles collection ( NullReferenceException Class ), it will not set the DataGrid's DataSource property.

See

Windows Forms Sample topics | Hide DataSource for the DataGrid in an array of DataColumn |

相关文章
  • Hide DataGrid DataSource is DataTable in the DataColumn (Visual C #) 2010-05-13

    Code: Hidden in the DataGrid's DataSource to DataTable DataColumn (Visual C #) This example hidden in existing Windows Forms DataGrid control to display the DataTable object "X" column. Example Copy private void HideColumnOfDataSet() { System.Da

  • Hide DataGrid DataSource is DataTable of the DataColumn (Visual C #) 2010-05-13

    Code: Hidden in the DataGrid's DataSource to DataTable DataColumn (Visual C #) The sample hidden in the existing Windows Forms DataGrid control to display the DataTable object "X" column. Example Copy private void HideColumnOfDataSet() { System.

  • DataTable数据导出成Excel文件的小例子 2013-12-12

    DataTable数据导出成Excel文件的小例子,需要的朋友可以参考一下 /// /// 将DataTable中的数据导出到指定的Excel文件中 /// /// Web页面对象 /// 包含被导出数据的DataTable对象 /// Excel文件的名称 public static void Export(System.Web.UI.Page page,System.Data.DataTable tab,string FileName) { System.Web.HttpResponse h

  • C#中DataTable排序.检索.合并等操作实例 2014-01-04

    这篇文章主要介绍了C#中DataTable排序.检索.合并等操作实例,其中详细介绍了DataTable.Select的一些注意问题和使用技巧等,需要的朋友可以参考下 一.排序1.获取DataTable的默认视图 2.对视图设置排序表达式 3.用排序后的视图导出的新DataTable替换就DataTable(Asc升序可省略,多列排序用","隔开) 1).重生法 dstaset.Tables.Add(dt) dataset.Tables(0).DefaultView.Sort = &qu

  • DataTable类Clone方法与Copy方法的区别分析 2014-08-13

    初学者可能不清楚DataTable类的Clone及Copy方法的区别,查msdn,可得到如下结论 DataTable.Clone 方法:克隆 DataTable 的结构,包括所有 DataTable 架构和约束. DataTable.Copy 方法:复制该 DataTable 的结构和数据. 我们可以编写如下的程序,进行验证: static string connStr = "Server=.\\sqlexpress;Initial Catalog=hr;Integrated Security=

  • C#创建.读取和修改Excel的方法 2015-02-05

    这篇文章主要介绍了C#创建.读取和修改Excel的方法,涉及C#使用Jet OLE DB操作Excel的技巧,非常具有实用价值,需要的朋友可以参考下 本文实例讲述了C#创建.读取和修改Excel的方法.分享给大家供大家参考.具体如下: windows下我们可以通过 Jet OLE DB访问Excel,就行访问数据库一样 // Namespaces, Variables, and Constants using System; using System.Configuration; using S

  • RichFaces learning (seven )---- Data Iteration Components 2010-11-11

    1. DataTable common control class are: <rich:dataTable> <rich:dataDefinitionList> <rich:dataOrderedList> <rich:dataList> <rich:dataGrid> 2. <rich:dataTable> 1) <rich:dataTable> has all the basic functions <h:da

  • raport machine report 2010-12-06

    private void btnBookIn_Click (object sender, EventArgs e) { DataTable dt1 = new DataTable (); if (this.dgvListSoure.DataSource! = null) { dt1 = this.dgvListSoure.DataSource as DataTable; } else { for (int i = 0; i <dgvListSoure.Columns.Count; i + +)

  • asp.net与excel互操作实现代码 2013-12-28

    将datatable中的数据导出到指定的excel文件中 /// <summary> /// 将datatable中的数据导出到指定的excel文件中 /// </summary> /// <param name="page">web页面对象</param> /// <param name="tab">包含被导出数据的datatable对象</param> /// <param name=

  • Some use intelligent device database 2010-09-15

    Communications component for the following hardware and data communication protocols to support: Serial I / O support for Remote Access Service (RAS) Transmission Control Protocol / Internet Protocol (TCP / IP) Local area network (LAN) Call API (TAPI

  • C # operate SQL server ce [Mobile device-side] 2010-11-03

    Organize paragraphs operating SQL Server Mobile database used C # code, for access to SQL Server Mobile development just friends for reference. 1. Create a database / / Create a database File.Delete ("Test.sdf"); SqlCeEngine engine = new SqlCeEn

  • Repeater in a row on the received data item in the value of a column 2010-12-27

    How do I get Repeater data item in a row in a column value. Master drifting ~ ~ ~ In fact, 'Repeater data in each row is an object, as to what type of the object, depends on your background bound data source. We usually will bind a table (DataTable),

  • WinForm实现基于BindingSource的方法扩展 2014-06-07

    这篇文章主要介绍了WinForm实现基于BindingSource的方法扩展,需要的朋友可以参考下 本文实例展示了WinForm实现基于BindingSource的方法扩展,共享给大家供大家参考.具体方法如下: 关键代码如下: using System; using System.Collections.Generic; using System.Reflection; using System.Windows.Forms; namespace WinFormUtilHelpV2 { /// <

  • 手把手教学:详解Swift中的iOS设计模式 2014-09-28

    设计模式针对软件设计中的常见问题,提供了一些可复用的解决方案,它向开发者提供了模板,使其更易于写出逻辑清晰.可重用的代码.正确地使用设计模式可以降低代码之间的耦合度,轻松更新或替换项目中使用的组件. 说到设计模式,相信大家都不陌生,但是又有多少人知道它背后的真正含义?绝大多数程序员都知道设计模式十分重要,不过关于这个话题的文章却不是很多,开发者们在开发的时候有时也不太在意设计模式方面的内容. 设计模式针对软件设计中的常见问题,提供了一些可复用的解决方案,开发者可以通过这些模板写出易于理解且能够复

  • C#简单的通用基础字典实现方法 2015-04-22

    这篇文章主要介绍了C#简单的通用基础字典实现方法,包含了字典的索引.记录.回调与查询等技巧,需要的朋友可以参考下 本文实例讲述了C#简单的通用基础字典实现方法.分享给大家供大家参考.具体实现方法如下: using System; using System.Collections.Generic; using System.Linq; using System.Text; using Alif.Alif_WSAPI; using System.Data; using System.Windows.

  • IOS设计模式之二(门面模式,装饰器模式) 2014-12-26

    门面模式针对复杂的子系统提供了单一的接口,不需要暴漏一些列的类和API给用户,你仅仅暴漏一个简单统一的API. 下面的图解释了这个概念: 这个API的使用者完全不需要关心背后的复杂性.这个模式非常适合有一大堆很难使用或者理解的类的情况. 门面模式解耦了使用系统的代码和需要隐藏的接口和实现类.它也降低了外部代码对内部子系统的依赖性.当隐藏在门面之后的类很容易发生变化的时候,此模式就很有用了,因为当背后的类发生变化的时候,门面类始终保持了同样的API. 举个例子来说,如果有一天你想取代后端服务,你不

  • Finishing second extjs project 2011-01-09

    girdpanel curd /** * viewConfig Role in the attempt on the grid's UI config object , Available configuration of any Ext.grid.GridView * Options can be specified here . * forceFit True To automatically expand / shrink to fit the width of the column gr

  • asp DataTable添加列和行的三种方法 2014-10-06

    DataTable添加列和行的方法,大家可以参考下下面的代码. #region 方法一: DataTable tblDatas = new DataTable("Datas"); DataColumn dc = null; dc = tblDatas.Columns.Add("ID", Type.GetType("System.Int32")); dc.AutoIncrement = true;//自动增加 dc.AutoIncrementSee

  • YUI Changing the Contents of the DataTable 2010-04-10

    Working with the YUI DataTable (Updated for v2.6.0), Part 2: Changing the Contents of the DataTable October 27, 2008 at 8:23 am by Satyam | In Development | 28 Comments Don't miss Part One of this series, in which Satyam explores practical steps on g

  • DataReader and DataSet, DataGrid and DataList 2010-08-18

    What is the difference DataReader and DataSet? DataSet represents a data set, the data in the memory cache. Can include multiple tables Non DataSet connection database connection-oriented. Sql all read the table in the buffer pool, and disconnect the