我只回答第二个问题。除了将允许排序属性选中以外,还需要为DataGrid.SortCommand事件写一个响应程序,其主要部分是这条语句:
myDataView.Sort=e.SortExpression;
其中myDataView是你的DataGrid的数据源的DataView,然后重新绑定一下就可以了。
myDataView.Sort=e.SortExpression;
其中myDataView是你的DataGrid的数据源的DataView,然后重新绑定一下就可以了。
解决方案 »
- webBrowser的HtmlDocument 出现意外
- 初学者新人乍到 问几个小白问题
- C#导出相关:导出EXCEL,但为什么有的机子会导出正确的EXCEL,但是有的机子只会用IE强制打开,郁闷了很久了
- CheckBoxList 控件返回数据库如何设定选中项
- 面向对象题目求解!!
- 代码工具codesmith的
- 50分求c#关闭某个应用程序的方法.
- 求救,遇到“在此上下文中不允许使用名称 "**"。.....不允许使用列名。”
- 类型化的DataSet里的自动编号,与数据源的自动编号不一致,
- C#编写数据库应用程序方便吗?
- 诚征“情人节”活动方案--深圳地区
- 我刚装的.net,不知怎么搞的,不能新建项目,cpu跑到100%,各位仁兄,帮帮忙,我该怎么处理?
第三个问题
得用Template column
// code assumes you have a DataSet named myDataSet, a table named "EastCoastSales" and a DataGrid myDataGrid
//STEP 1: Create a DataTable style object and set properties if required.
DataGridTableStyle ts1 = new DataGridTableStyle();
//specify the table from dataset (required step)
ts1.MappingName = "EastCoastSales";
// Set other properties (optional step)
ts1.AlternatingBackColor = Color.LightBlue;
//STEP 2: Create a string column and add it to the tablestyle
DataGridColumnStyle TextCol = new DataGridTextBoxColumn();
TextCol.MappingName = "custName"; //from dataset table
TextCol.HeaderText = "Customer Name";
TextCol.Width = 250;
ts1.GridColumnStyles.Add(TextCol);
//STEP 3: Create an int column style and add it to the tablestyle
//this requires setting the format for the column through its property descriptor
PropertyDescriptorCollection pdc = this.BindingContext
[myDataSet, "EastCoastSales"].GetItemProperties();
//now created a formated column using the pdc
DataGridDigitsTextBoxColumn csIDInt =
new DataGridDigitsTextBoxColumn(pdc["CustID"], "i", true);
csIDInt.MappingName = "CustID";
csIDInt.HeaderText = "CustID";
csIDInt.Width = 100;
ts1.GridColumnStyles.Add(csIDInt);
//STEP 4: Add the checkbox
DataGridColumnStyle boolCol = new DataGridBoolColumn();
boolCol.MappingName = "Current";
boolCol.HeaderText = "Info Current";
//uncomment this line to get a two-state checkbox
//((DataGridBoolColumn)boolCol).AllowNull = false;
boolCol.Width = 150;
ts1.GridColumnStyles.Add(boolCol);
//STEP 5: Add the tablestyle to your datagrid's tablestlye collection
myDataGrid.TableStyles.Add(ts1);