本文介绍WPF平台下C1FlexGrid的行选,包括方法,模式等。
C1FlexGrid提供了简单快速的选择方式:Select方法,可以容易的选择单元格/行/行区域。比如通过C1FlexGrid的SelectionMode属性,就可以选择使用。设置SelectionMode为Cell,然后通过Select方法的CellRange参数,它可以选择CellRange的第一个单元格。
为了选择整行,下面我们就来研究下不使用鼠标,如何来实现。
设置SelectionMode
首先,设置SelectionMode属性为Row,然后我们就可以选择整行。
代码参考:
<c1:C1FlexGrid x:Name="c1FlexGrid1" HorizontalAlignment="Left" Margin="12,12,0,0" Loaded="c1FlexGrid1_Loaded" SelectionMode="Row" Height="350" AutoGenerateColumns="True" VerticalAlignment="Top" />
选择行
然后使用Select方法选择特定的行(比如,第六行)
c1FlexGrid1.Select(5, 0, 5, c1FlexGrid1.Columns.Count - 1, true);
当FlexGrid包含记录比较多的时候,竖直的滚动条会出现,然后如果要选择第20行,并且要滚动当前行到视图内。就需要处理FlexGrid的Loaded事件,调用Select方法。
代码:
private void c1FlexGrid1_Loaded(object sender, RoutedEventArgs e) { c1FlexGrid1.Select(16, 0, 16, c1FlexGrid1.Columns.Count - 1, true); c1FlexGrid1.Focus(); }
注意:调用Focus方法。调用这个方法就不需要额外点击grid。
如图:
演示示例请下载:C1FlexGridWPF.zip (12.02 kb)
更多资源
C1FlexGrid在线英文产品文档地址:
http://helpcentral.componentone.com/nethelp/C1FlexGridWPFSilv/ComponentOne%20FlexGrid%20for%20WPF%20and%20Silverlight.html
如果你对C1FlexGrid感兴趣,请到我们的官网下载最新版本:/download/?pid=6
如果你有疑问,可以到GCDN论坛获得技术支持:http://gcdn.grapecity.com.cn/showforum-138.html