web的wpf开发中datagrid合并单元格问题

corywind 2011-03-14 03:19:26
弄了一下午的wpf多亏各位帮忙把设置背景色算是解决了,结果现在又来问题了,要动态合并单元格,并且将合并后的单元格边线加粗加黑,一脑袋浆糊现在,还得请各位高手相助,谢谢
...全文
755 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
wlj1800 2011-12-25
  • 打赏
  • 举报
回复
看看怎么弄的,现在也在弄这个问题
lizhibin11 2011-03-15
  • 打赏
  • 举报
回复
sorry,对这种需求我不会费事使用datagrid,而是直接画

<Page x:Class="WpfBrowserApplication1.Page1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
xmlns:local="clr-namespace:WpfBrowserApplication1"
d:DesignHeight="700" d:DesignWidth="1000"
Title="Page1">
</Page>


using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Data;

namespace WpfBrowserApplication1
{
/// <summary>
/// Page1.xaml 的交互逻辑
/// </summary>
public partial class Page1 : Page
{
DrawingVisual dv = new DrawingVisual();
DataTable dt = new DataTable();
public Page1()
{
this.VisualEdgeMode = EdgeMode.Aliased;
dt.Columns.Add("A", typeof(int));
dt.Columns.Add("B", typeof(DateTime));
for (int i = 0; i < 60; i++)
{
DataRow dr = dt.NewRow();
dr[0] = i;
dr[1] = DateTime.Now.AddDays(-14).AddDays(i % 31);
dt.Rows.Add(dr);
}
dt.AcceptChanges();

InitializeComponent();
Pen blackp = new Pen(Brushes.Black, 1);
System.Globalization.CultureInfo ci = new System.Globalization.CultureInfo("zh-cn");
FlowDirection fd = FlowDirection.LeftToRight;
Typeface tf = new Typeface("宋体");
double d = 12;
using (DrawingContext dc = dv.RenderOpen())
{
for (int i = 0; i < 5; i++)
{
dc.DrawRectangle(null, blackp, new Rect(217 * i, 0, 217, 30));
dc.DrawText(new FormattedText("第" + (i + 1).ToString() + "周", ci, fd, tf, d, Brushes.Black), new Point(217 * i + 70, 10));
}
for (int i = 0; i < 35; i++)
dc.DrawRectangle(null, blackp, new Rect(31 * i, 30, 31, 30));
int w = new DateTime(2011, 3, 1).DayOfWeek.GetHashCode();
for(int i = w;i<w + 31;i++)
dc.DrawText(new FormattedText((i - w + 1).ToString(), ci, fd, tf, d, Brushes.Black), new Point(31 * i + 5, 40));
for (int i = 0; i < 35; i++)
dc.DrawRectangle(null, blackp, new Rect(31 * i, 60, 31, 60));
for (int i = 0; i < dt.Rows.Count; i++)
{
int week = ((DateTime)dt.Rows[i][1]).DayOfWeek.GetHashCode();
int day = ((DateTime)dt.Rows[i][1]).Day;
string s = dt.Rows[i][0].ToString();
double left = (double)(week + (day + week / 7 * 7 + 1) * 31 + 5);
double top = i > 30 ? 100 : 70;
dc.DrawText(new FormattedText(s, ci, fd, tf, d, Brushes.Black), new Point(left, top));
}
}
}
protected override int VisualChildrenCount
{
get
{
return 1;
}
}
protected override Visual GetVisualChild(int index)
{
return dv;
}
}
}
corywind 2011-03-15
  • 打赏
  • 举报
回复
我说一下,具体的效果,就是列头显示对应数据的月的周,第一周,第二周,第三周。。。。
下面对应的是天数,每周对应哪几天,因为每个月开始和结束的时候那一周不一定是7点,所以这个列头就需要临时来合并起来,
行头就是有的行头是一个,但是要对应两行数据
lizhibin11 2011-03-15
  • 打赏
  • 举报
回复
这个有三种方式,最简单的是第一种:
1、生成新的数据源,也就是查询结果的数据源,数据源里面先实现合并等内容,然后绑定到标准datagrid。
2、还是原来的数据源,datagrid重新定义列头,然后显示时通过Converter来绑定合并后的数据。
3、使用DrawingVisual类来画,这个你可以搜索一下msdn里面这个类。这种方式最自由,没拘束,效率高。
没有具体需求实在没办法给你做示例程序,不好意思。
yalan 2011-03-15
  • 打赏
  • 举报
回复
使用WPF的Grid组件的xxxxxSpan方法合并单元格

http://www.cnblogs.com/DragonInSea/archive/2009/04/10/1433117.html
corywind 2011-03-15
  • 打赏
  • 举报
回复
不产生报表,只是一个显示的效果就可以了,是一个查询页面不需要增删改。
就是个datagrid
lizhibin11 2011-03-15
  • 打赏
  • 举报
回复
只是产生报表时是这个样子对吧?录入和修改时还是标准的datagrid吧?
corywind 2011-03-15
  • 打赏
  • 举报
回复
行头只要能合并,就成,列头是根据不同的列数来合并的并且需要是link的表现方式
置合并列头或者单元格,数据行不改变。
谢谢!
lizhibin11 2011-03-15
  • 打赏
  • 举报
回复
你能不能明确说一下你这个需求,比如仅仅合并列头,还是数据部分也要合并,这种合并后的表格要可以编辑,还是仅仅显示.
corywind 2011-03-15
  • 打赏
  • 举报
回复
合并列头或者行头也成啊

110,537

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧