datagrid

浅谈DataGridTableStyle心得

 ̄綄美尐妖づ 提交于 2020-03-17 03:02:47
在开发数据DataGrid显示时候通常会遇到自定义DataGrid的列显示, 比如经常会提到的, 如何单击一行显示某种颜色 如何点击到某个单元格不显示编辑框 如何自定义一列的显示,比如本来有个标记位flag为0,本行背景显示为白色等等, 此类问题归根到底还是要靠 DataGridTableStyle 和 System.Windows.Forms.DataGridColumnStyle 这两个类来完成. DataGridColumnStyle 是定义一列显示的样式 DataGridTableStyle 是定义整个datagrid的实现样式. dts.GridColumnStyles.Clear();//将column的style清除 for ( int i = 0 ;i < Boxs.Count;i ++ ) { dts.GridColumnStyles.Add((DataGridTextBoxColumn)Boxs[i]);//把所有的columnstyle附加上去 } Employee_lst.TableStyles.Add(dts);//最后把datatablestyle附加到datagrid上去 还要注意每一个columnstryl都要对应到列,否则会出错. DatatableStyle也要对应到表. xxx.MappingName= yyy;

共享GridView DataGrid DataTable导出到Excel代码

萝らか妹 提交于 2020-03-10 03:46:05
下面是一个导出Excel文件的代码。 code using System; using System.Collections.Generic; using System.Text; using System.Data; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; namespace Test { /**/ /// <summary> /// 重载样例 /// </summary> public class GridViewExport : ExcelExport { public GridViewExport(DataTable dt) : base (dt, true ) { } public override void GridViewBoundEvent( object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { // e.Row.Cells[1]

asp.net Datagrid 资源

老子叫甜甜 提交于 2020-03-09 08:43:17
A Remedy for DataGrid Vertigo http://www.dotnetjunkies.com/tutorials.aspx?tutorialid=763 A Truly Excel-like Grid Control http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndive/html/Data02142002.asp?frame=true Accessing Datagrid Information http://www.dotnetjunkies.com/tutorials.aspx?tutorialid=355 Adding a "Totals" Field in a Datagrid http://www.dotnetjunkies.com/tutorials.aspx?tutorialid=96 Adding a Blank Row to a Datagrid (Used to INSERT rather than UPDATE) http://www.dotnetjunkies.com/tutorials.aspx?tutorialid=186 Adding a DropDownList to an Editable Datagrid http://www

WPF之DataGrid应用

梦想与她 提交于 2020-03-07 00:13:39
http://blog.csdn.net/sanjiawan/article/details/6785394 1.数据绑定 2.DataGrid的增改删功能 3.DataGrid的分页实现 4.DataGrid的样式设计 先上一张截图,让你大概知道自己需要的功能是否在这张图里有所实现。 PS:使用技术:WPF + ADO.NET Entity Framework 1.数据绑定(涉及DataGrid绑定和Combox绑定) 在DataGrid 中同时包含“自动生成列”与“用户自定义列” 由属性AutoGenerateColumns控制。 默认情况下, DataGrid 将根据数据源自动生成列。 下图列出了生成的列类型。 如果AutoGenerateColumns="True" ,我们只需要如下几行代码 <DataGrid Name="dataGrid1" AutoGenerateColumns="True" /> 后台dataGrid1.ItemsSource = infoList; //infoList为内容集合(这是我从数据库中获取的记录集合 类型为List<T>) PS:因为这里给dataGrid1绑定了数据源,所以下面绑定的字段都是infoList中的字段名称,同样也对应着我数据表中的字段名。里面包含FID,公司名称,职员姓名,性别,年龄,职务。解释下

datagrid的显示控制

杀马特。学长 韩版系。学妹 提交于 2020-03-06 08:43:06
1、在DataGrid中的ItemDataBound事件中加入以下代码即可实现鼠标指定列的特殊显示,当鼠标移到DataGrid中一条数据时,该条数据以特殊颜色显示,当鼠标移开时,该条数据又以另外一种特殊颜色显示 If (e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem) Then e.Item.Attributes.Add("onmouseover", "this.style.backgroundColor='#E4EDF9'") e.Item.Attributes.Add("onmouseout", "this.style.backgroundColor='#F1F3F5'") End If 2、某条记录颜色的变化 if((e.Item.ItemType == ListItemType.Item)||(e.Item.ItemType == ListItemType.AlternatingItem)) { if((e.Item.Cells[7].Text!="")&&(Convert.ToDouble(e.Item.Cells[7].Text) < 0 )) { e.Item.Style.Add("COLOR","red"); } } 来源: https:/

DataGrid显示主次关系(C#)

狂风中的少年 提交于 2020-03-06 08:40:33
//========HTML页面 <asp:datagrid id="dl_fenlei" Width="442px" HorizontalAlign="Left" Font-Size="Larger" BorderStyle="Solid" AllowSorting="True" BorderColor="White" ShowHeader="False" CellPadding="0" AutoGenerateColumns="False" BorderWidth="0px" runat="server"> <Columns> <asp:TemplateColumn> <ItemTemplate> <table border="0" cellpadding="0" cellspacing="0" width="442"> <!-- fwtable fwsrc="????¨1??" fwbase="index_r4_c4.jpg" fwstyle="Dreamweaver" fwdocid = "71301705" fwnested="0" --> <tr> <td><img src="skin/spacer.gif" width="442" height="1" border="0" alt=""></td> <td><img src="skin/spacer.gif"

Not refreshing in WPF with DataGrid

霸气de小男生 提交于 2020-03-06 04:37:32
问题 Sorry, I have seen this questioned asked a couple of times here already, but none of the answers have solved my problem. public MainWindow() { _PropertyTenantData = new DataTable(); _PropertyTenantData.Columns.Add(new DataColumn("Property", typeof(string))); _PropertyTenantData.Columns.Add(new DataColumn("Tenant", typeof(string))); DBConnect RentalDatabase = new DBConnect(); List<string>[] list = new List<string>[2]; list = RentalDatabase.SelectPropertyTenant(); var row = _PropertyTenantData

WPF DataGrid 中的DataGridComboBoxColumn 使用

穿精又带淫゛_ 提交于 2020-03-05 00:19:37
步骤一、新建枚举类型 public enum WeightUnits { 克,斤,公斤,千克,吨,毫克 }; 步骤二、在资源中创建 数据提供者 <UserControl x:Class="XXXXView" xmlns:core="clr-namespace:System;assembly=mscorlib" xmlns:local="clr-namespace:<枚举所在的命名空间>" /> <UserControl.Resources> <ObjectDataProvider x:Key="myEnum" MethodName="GetValues" ObjectType="{x:Type core:Enum}"> <ObjectDataProvider.MethodParameters> <x:Type Type="local:WeightUnits"/> </ObjectDataProvider.MethodParameters> </ObjectDataProvider> </UserControl.Resources> 之前要生命一些XML空间 xmlns:core="clr-namespace:System;assembly=mscorlib" xmlns:local="clr-namespace:Qtrunk.Modules.SiteManagement" 步骤三

WPF 动态生成DataGrid及动态绑定解决方案

泪湿孤枕 提交于 2020-03-04 21:51:38
一、场景 有过WPF项目经验的朋友可能都知道,如果一个DataGrid要绑定静态的数据是非常的简单的(所谓静态是指绑定的数据源的类型是静态的),如下图所示,想要显示产品数据,只需绑定到一个产品列表即可,这个大家都清楚,所以这个要讲的肯定不是这个。 但是现在有一个新的需求,根据所选择产品的不同,要动态生成第二个表格中的不同数据,以便进行编辑,如下图1、2所示,当选择的产品不同时,第二个表格显示的内容是完全不一样的。 这样就会产生一个问题,无法直接对第二个表格进行绑定,因为它的数据源类型都是不一样的,无法按照传统方法进行绑定。如何解决,先自己思考一下,也许会有更好的解决方案。 二、思路 1、定义Domain 既然无法知道要绑定的数据类型是什么,因为它是动态的,无法事先预知的,根据所选择的产品(因为产品数据都存储于DB中,所以将类型定义于Domain项目中)不同而变化的。那么可以在 Product 中定义 SKUFields 属性用于代表产品可显示的字段。产品定义如下所示。 /// <summary> /// 产品 /// </summary> [Table("Product")] public class Product { public int ProductId { get; set; } public string ProductDesc { get; set; } public

WPF DataGrid自动生成行号

♀尐吖头ヾ 提交于 2020-03-04 21:50:57
在使用WPF进行应用程序的开发时,经常会为DataGrid生成行号,这里主要介绍一下生成行号的方法。通常有三种方法,这里主要介绍其中的两种,另一种简单提一下。 1. 直接在LoadingRow事件中操作。 这种方式是在code behind文件中操作。即相应的*.xaml.cs文件。 代码如下: this .dataGridSoftware.LoadingRow += new EventHandler<DataGridRowEventArgs>( this .DataGridSoftware_LoadingRow); // ... private void DataGridSoftware_LoadingRow( object sender, DataGridRowEventArgs e) { e.Row.Header = e.Row.GetIndex() + 1 ; } 这种方式最为简洁,也最容易理解。 但现在很多应用程序的开发都采用了MVVM(Model-View-ModelView)的开发模式。这种模式通常为了更好的解耦,所以通常不会在code behind文件中加入代码,为了在这种方式下实现上面的自动生成行号的操作,可以采用下面要讲到第二种方法。但我个人认为,不能太死板的使用MVVM,对于生成行号这种需求,不是业务逻辑的范畴,而是view的范畴,所以放到code