ASPxGridView 中,如何合并列与列之间的虚线? ASPxGridView 中,如何合并列与列之间的虚线?请大师帮忙!例如:如何把变成 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 对要去掉的列设置 CellStyle属性 <dxwgv:GridViewDataTextColumn Caption="符号" VisibleIndex="2"> <CellStyle> <Border BorderWidth=0 /> <BorderLeft BorderWidth=0/> <BorderRight BorderWidth=0/> </CellStyle> </dxwgv:GridViewDataTextColumn> public class ASPxGridViewCellMerger { ASPxGridView grid; Dictionary<GridViewDataColumn, TableCell> mergedCells = new Dictionary<GridViewDataColumn, TableCell>(); Dictionary<TableCell, int> cellRowSpans = new Dictionary<TableCell, int>(); public ASPxGridViewCellMerger(ASPxGridView grid) { this.grid = grid; Grid.HtmlRowCreated += new ASPxGridViewTableRowEventHandler(grid_HtmlRowCreated); Grid.HtmlDataCellPrepared += new ASPxGridViewTableDataCellEventHandler(grid_HtmlDataCellPrepared); } public ASPxGridView Grid { get { return grid; } } void grid_HtmlDataCellPrepared(object sender, ASPxGridViewTableDataCellEventArgs e) { if (cellRowSpans.ContainsKey(e.Cell)) { e.Cell.RowSpan = cellRowSpans[e.Cell]; } } void grid_HtmlRowCreated(object sender, ASPxGridViewTableRowEventArgs e) { if (Grid.GetRowLevel(e.VisibleIndex) != Grid.GroupCount) return; for (int i = e.Row.Cells.Count - 1; i >= 0; i--) { DevExpress.Web.ASPxGridView.Rendering.GridViewTableDataCell dataCell = e.Row.Cells[i] as DevExpress.Web.ASPxGridView.Rendering.GridViewTableDataCell; if (dataCell != null) { MergeCells(dataCell.DataColumn, e.VisibleIndex, dataCell); } } } void MergeCells(GridViewDataColumn column, int visibleIndex, TableCell cell) { bool isNextTheSame = IsNextColumnHasSameData(column, visibleIndex); if (isNextTheSame) { if (!mergedCells.ContainsKey(column)) { mergedCells[column] = cell; } } if (IsPrevColumnHasSameData(column, visibleIndex)) { ((TableRow)cell.Parent).Cells.Remove(cell); if (mergedCells.ContainsKey(column)) { TableCell mergedCell = mergedCells[column]; if (!cellRowSpans.ContainsKey(mergedCell)) { cellRowSpans[mergedCell] = 1; } cellRowSpans[mergedCell] = cellRowSpans[mergedCell] + 1; } } if (!isNextTheSame) { mergedCells.Remove(column); } } bool IsNextColumnHasSameData(GridViewDataColumn column, int visibleIndex) { //is it the last visible row if (visibleIndex >= Grid.VisibleStartIndex + Grid.VisibleRowCount - 1) return false; return IsSameData(column.FieldName, visibleIndex, visibleIndex + 1); } bool IsPrevColumnHasSameData(GridViewDataColumn column, int visibleIndex) { ASPxGridView grid = column.Grid; //is it the first visible row if (visibleIndex <= Grid.VisibleStartIndex) return false; return IsSameData(column.FieldName, visibleIndex, visibleIndex - 1); } bool IsSameData(string fieldName, int visibleIndex1, int visibleIndex2) { // is it a group row? if (Grid.GetRowLevel(visibleIndex2) != Grid.GroupCount) return false; return object.Equals(Grid.GetRowValues(visibleIndex1, fieldName), Grid.GetRowValues(visibleIndex2, fieldName)); } } protected void ASPxGridViewDelivery_HtmlRowCreated(object sender, ASPxGridViewTableRowEventArgs e) { //if the first data row has been added if (e.RowType == DevExpress.Web.ASPxGridView.GridViewRowType.Data && e.VisibleIndex == ASPxGridViewDelivery.PageIndex * ASPxGridViewDelivery.SettingsPager.PageSize) { Table table = e.Row.Parent as Table; if (table != null) { TableRow row = new TableRow(); int index = 0; while (index < ASPxGridViewDelivery.VisibleColumns.Count) { TableCell cell = new TableCell(); cell.Text = ASPxGridViewDelivery.VisibleColumns[index++].ToString(); if (index < ASPxGridViewDelivery.VisibleColumns.Count) { cell.Text += " - " + ASPxGridViewDelivery.VisibleColumns[index++].ToString(); cell.ColumnSpan = 2; } cell.HorizontalAlign = HorizontalAlign.Center; //if it is not the last column if (index < ASPxGridViewDelivery.VisibleColumns.Count) { cell.BorderStyle = BorderStyle.Solid; cell.BorderWidth = Unit.Pixel(0); cell.Style["BORDER-RIGHT-WIDTH"] = "1px"; cell.BorderColor = System.Drawing.Color.Gray; } row.Cells.Add(cell); } table.Rows.AddAt(0, row); } } } 求教各位,帮帮忙!!! multimedia timer与queue Timer的区别 请问一个C#的多线程问题! 错误分析,大家帮个忙啊 byte[] 简单问题 关于两个线程的交互问题,帮帮忙,谢谢! 请问 WinForm中的 DataGrid 如何自定义它的ColumnHeader? C#操作FTP问题 DataGrid 的 Save 问题。 重载MenuItem时的问题????????? ASPxGridView 中,如何合并列与列之间的虚线? 问一个excel数字和列名转换的问题
<dxwgv:GridViewDataTextColumn Caption="符号" VisibleIndex="2">
<CellStyle>
<Border BorderWidth=0 />
<BorderLeft BorderWidth=0/>
<BorderRight BorderWidth=0/>
</CellStyle>
</dxwgv:GridViewDataTextColumn>
{
ASPxGridView grid;
Dictionary<GridViewDataColumn, TableCell> mergedCells = new Dictionary<GridViewDataColumn, TableCell>();
Dictionary<TableCell, int> cellRowSpans = new Dictionary<TableCell, int>(); public ASPxGridViewCellMerger(ASPxGridView grid)
{
this.grid = grid;
Grid.HtmlRowCreated += new ASPxGridViewTableRowEventHandler(grid_HtmlRowCreated);
Grid.HtmlDataCellPrepared += new ASPxGridViewTableDataCellEventHandler(grid_HtmlDataCellPrepared);
} public ASPxGridView Grid { get { return grid; } }
void grid_HtmlDataCellPrepared(object sender, ASPxGridViewTableDataCellEventArgs e)
{
if (cellRowSpans.ContainsKey(e.Cell))
{
e.Cell.RowSpan = cellRowSpans[e.Cell];
}
}
void grid_HtmlRowCreated(object sender, ASPxGridViewTableRowEventArgs e)
{
if (Grid.GetRowLevel(e.VisibleIndex) != Grid.GroupCount) return;
for (int i = e.Row.Cells.Count - 1; i >= 0; i--)
{
DevExpress.Web.ASPxGridView.Rendering.GridViewTableDataCell dataCell = e.Row.Cells[i] as DevExpress.Web.ASPxGridView.Rendering.GridViewTableDataCell;
if (dataCell != null)
{
MergeCells(dataCell.DataColumn, e.VisibleIndex, dataCell);
}
}
} void MergeCells(GridViewDataColumn column, int visibleIndex, TableCell cell)
{
bool isNextTheSame = IsNextColumnHasSameData(column, visibleIndex);
if (isNextTheSame)
{
if (!mergedCells.ContainsKey(column))
{
mergedCells[column] = cell;
}
}
if (IsPrevColumnHasSameData(column, visibleIndex))
{
((TableRow)cell.Parent).Cells.Remove(cell);
if (mergedCells.ContainsKey(column))
{
TableCell mergedCell = mergedCells[column];
if (!cellRowSpans.ContainsKey(mergedCell))
{
cellRowSpans[mergedCell] = 1;
}
cellRowSpans[mergedCell] = cellRowSpans[mergedCell] + 1;
}
}
if (!isNextTheSame)
{
mergedCells.Remove(column);
}
}
bool IsNextColumnHasSameData(GridViewDataColumn column, int visibleIndex)
{
//is it the last visible row
if (visibleIndex >= Grid.VisibleStartIndex + Grid.VisibleRowCount - 1) return false;
return IsSameData(column.FieldName, visibleIndex, visibleIndex + 1);
}
bool IsPrevColumnHasSameData(GridViewDataColumn column, int visibleIndex)
{
ASPxGridView grid = column.Grid;
//is it the first visible row
if (visibleIndex <= Grid.VisibleStartIndex) return false;
return IsSameData(column.FieldName, visibleIndex, visibleIndex - 1);
}
bool IsSameData(string fieldName, int visibleIndex1, int visibleIndex2)
{
// is it a group row?
if (Grid.GetRowLevel(visibleIndex2) != Grid.GroupCount) return false;
return object.Equals(Grid.GetRowValues(visibleIndex1, fieldName), Grid.GetRowValues(visibleIndex2, fieldName));
} }
{
//if the first data row has been added
if (e.RowType == DevExpress.Web.ASPxGridView.GridViewRowType.Data && e.VisibleIndex == ASPxGridViewDelivery.PageIndex * ASPxGridViewDelivery.SettingsPager.PageSize)
{
Table table = e.Row.Parent as Table;
if (table != null)
{
TableRow row = new TableRow();
int index = 0;
while (index < ASPxGridViewDelivery.VisibleColumns.Count)
{
TableCell cell = new TableCell();
cell.Text = ASPxGridViewDelivery.VisibleColumns[index++].ToString();
if (index < ASPxGridViewDelivery.VisibleColumns.Count)
{
cell.Text += " - " + ASPxGridViewDelivery.VisibleColumns[index++].ToString();
cell.ColumnSpan = 2;
}
cell.HorizontalAlign = HorizontalAlign.Center;
//if it is not the last column
if (index < ASPxGridViewDelivery.VisibleColumns.Count)
{
cell.BorderStyle = BorderStyle.Solid;
cell.BorderWidth = Unit.Pixel(0);
cell.Style["BORDER-RIGHT-WIDTH"] = "1px";
cell.BorderColor = System.Drawing.Color.Gray;
}
row.Cells.Add(cell);
}
table.Rows.AddAt(0, row);
}
}
}