找回密码
 立即注册

QQ登录

只需一步,快速开始

sygmonitor

论坛元老

16

主题

60

帖子

1万

积分

论坛元老

积分
12550

活字格认证微信认证勋章

sygmonitor
论坛元老   /  发表于:2013-9-10 17:20  /   查看:6932  /  回复:8
SILVERLIGHT5.0
C1DATAGRID中DataTemplate显示操作按钮必须点击一行前面的按钮(如图1)才可以实现图2的效果,我希望实现点击一行记录时,直接显示为图2的效果,请问有没有办法?

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x

8 个回复

倒序浏览
iceman
社区贡献组   /  发表于:2013-9-10 19:52:00
沙发
回复 1楼sygmonitor的帖子

sygmonitor 你好,

感谢你的问题反馈。

通过 DataTemplate 定制的模板是可以直接在单元格中显示的。
请问你是如何设置的?能否把你实现第二张图的代码共享出来,这样有助于加快问题解决进度。
回复 使用道具 举报
sygmonitor
论坛元老   /  发表于:2013-9-11 09:26:00
板凳
回复 2楼iceman的帖子
  1. <c1datagrid:C1DataGrid x:Name="grid" AutoGenerateColumns="False" Style="{StaticResource C1DataGrid}" HeadersVisibility="All"   FrozenColumnCount="2" Grid.Row="1">
  2.                                 <c1datagrid:C1DataGrid.Columns>
  3.                                     <!--<c1datagrid:DataGridTextColumn Header="操作" Binding="{Binding AKB020}"  FilterMemberPath="AKB020"  SortMemberPath="AKB020" />-->
  4.                                     <c1datagrid:DataGridTextColumn Header="统筹区" Binding="{Binding AREA_NAME}"  FilterMemberPath="AREA_NAME"  SortMemberPath="AREA_NAME" />
  5.                                     <c1datagrid:DataGridTextColumn Header="案件编号" Binding="{Binding CODE}" FilterMemberPath="CODE" SortMemberPath="CODE" />
  6.                                     <c1datagrid:DataGridTextColumn Header="案情描述" Binding="{Binding DESCRIPTION}" FilterMemberPath="DESCRIPTION" SortMemberPath="DESCRIPTION" />
  7.                                     <c1datagrid:DataGridTextColumn Header="立案批示意见" Binding="{Binding APPROVE_CONTENT}" FilterMemberPath="APPROVE_CONTENT" SortMemberPath="APPROVE_CONTENT" />
  8.                                 
  9.                                 </c1datagrid:C1DataGrid.Columns>                                
  10.                                 <c1datagrid:C1DataGrid.RowDetailsTemplate>
  11.                                     <DataTemplate>
  12.                                         <Grid Height="30" HorizontalAlignment="Stretch" Width="Auto">
  13.                                             <Grid.ColumnDefinitions>
  14.                                                 <ColumnDefinition Width="*"/>
  15.                                                 <!--<ColumnDefinition Width="120"/>
  16.                                                 <ColumnDefinition Width="120"/>-->                                                
  17.                                             </Grid.ColumnDefinitions>
  18.                                             <Button Content="详情" HorizontalAlignment="Right" VerticalAlignment="Center" Grid.Column="0" Margin="10,0,30,0" Width="80" Height="28" Cursor="Hand" Style="{StaticResource ButtonG2}" FontSize="12" Foreground="#FF262727" FontFamily="Microsoft YaHei"/>
  19.                                         </Grid>
  20.                                     </DataTemplate>
  21.                                 </c1datagrid:C1DataGrid.RowDetailsTemplate>
  22.                                 <c1datagrid:C1RowIndexHeaderBehavior.RowIndexHeaderBehavior>
  23.                                     <c1datagrid:C1RowIndexHeaderBehavior />
  24.                                 </c1datagrid:C1RowIndexHeaderBehavior.RowIndexHeaderBehavior>                                
  25.                             </c1datagrid:C1DataGrid>
复制代码
回复 使用道具 举报
iceman
社区贡献组   /  发表于:2013-9-11 12:07:00
地板
回复 3楼sygmonitor的帖子

sygmonitor 你好,

问题我已经清楚了,正在调查中,请稍候。
回复 使用道具 举报
iceman
社区贡献组   /  发表于:2013-9-12 12:08:00
5#
回复 4楼iceman的帖子

sygmonitor 你好,
不好意思,让你久等了。
C1DataGrid 的 RowDetailsTemplate 可见性通过 DetailsVisibility 属性控制,可以通过 CurrentCellChanged 事件来响应点击事件,在事件中设置 DetailsVisibility  属性:

  1.   void mygrid_CurrentCellChanged(object sender, C1.Silverlight.DataGrid.DataGridCellEventArgs e)
  2.         {
  3.             e.Cell.Row.DetailsVisibility =  System.Windows.Visibility.Visible;
  4.         }
复制代码
回复 使用道具 举报
sygmonitor
论坛元老   /  发表于:2013-9-12 14:31:00
6#
回复 5楼iceman的帖子

这样导致的结果是被点击过的都显示下拉模板了,我想达到只显示一行的效果!
我已通过自己的方法实现此效果,代码:
  1. void grid_SelectionChanged(object sender, DataGridSelectionChangedEventArgs e)
  2.         {
  3.             try
  4.             {
  5.                 C1DataGrid c1 = sender as C1DataGrid;               
  6.                 foreach (var item in c1.Rows)
  7.                 {
  8.                     item.DetailsVisibility = Visibility.Collapsed;                    
  9.                 }
  10.                 C1.Silverlight.DataGrid.DataGridCell cell = c1.CurrentCell;
  11.                 cell.Row.DetailsVisibility = Visibility.Visible;               
  12.             }
  13.             catch { }
  14.         }
复制代码
回复 使用道具 举报
iceman
社区贡献组   /  发表于:2013-9-12 19:27:00
7#
回复 6楼sygmonitor的帖子

是的,也是一种实现方法,我是通过以下方法实现的:

  1. C1.Silverlight.DataGrid.DataGridCell cell;
  2.         void mygrid_CurrentCellChanged(object sender, C1.Silverlight.DataGrid.DataGridCellEventArgs e)
  3.         {
  4.             if (!cell.Equals(e.Cell))
  5.             {
  6.                 cell.Row.DetailsVisibility = System.Windows.Visibility.Collapsed;
  7.                 e.Cell.Row.DetailsVisibility = System.Windows.Visibility.Visible;
  8.                 cell = e.Cell;
  9.             }
  10.         }
复制代码
回复 使用道具 举报
sygmonitor
论坛元老   /  发表于:2013-9-13 09:39:00
8#
回复 7楼iceman的帖子

你的方法我无法实现,报错误
回复 使用道具 举报
iceman
社区贡献组   /  发表于:2013-9-13 09:45:00
9#
回复 8楼sygmonitor的帖子

sygmonitor 你好,

报错的原因是 Cell 没有初始化,cell = this.mygrid.GetCell(0, 0);

  1. public MainPage()
  2.         {
  3.             InitializeComponent();

  4.             List<Student> stus = new List<Student>();
  5.             for (int i = 0; i < 50; i++)
  6.             {
  7.                 Student st = new Student();
  8.                 st.Name = "test";
  9.                 st.Score = 12;
  10.                 stus.Add(st);
  11.             }

  12.             this.mygrid.AutoGenerateColumns = false;
  13.             this.mygrid.ItemsSource = stus;
  14.             this.mygrid.CurrentCellChanged += new EventHandler<C1.Silverlight.DataGrid.DataGridCellEventArgs>(mygrid_CurrentCellChanged);
  15.             cell = this.mygrid.GetCell(0, 0);
  16.         }

  17.         C1.Silverlight.DataGrid.DataGridCell cell;
  18.         void mygrid_CurrentCellChanged(object sender, C1.Silverlight.DataGrid.DataGridCellEventArgs e)
  19.         {
  20.             if (!cell.Equals(e.Cell))
  21.             {
  22.                 cell.Row.DetailsVisibility = System.Windows.Visibility.Collapsed;
  23.                 e.Cell.Row.DetailsVisibility = System.Windows.Visibility.Visible;
  24.                 cell = e.Cell;
  25.             }
  26.         }
  27.     }

  28.     public class Student
  29.     {
  30.         public String Name { get; set; }
  31.         public int Score{get;set;}
  32.     }
复制代码
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 立即注册
返回顶部