回复 1楼zhuxialiang的帖子
zhuxialiang 你好
如果需要通过鼠标右键来选中行可以使用以下代码:
- public partial class MainWindow : Window
- {
- public MainWindow()
- {
- InitializeComponent();
- c1DataGrid1.DataContext = GetData();
- c1DataGrid1.CanUserAddRows = false;
- c1DataGrid1.SelectionMode = C1.WPF.DataGrid.DataGridSelectionMode.SingleRow;
- c1DataGrid1.LoadedRowPresenter += new EventHandler<C1.WPF.DataGrid.DataGridRowEventArgs>(c1DataGrid1_LoadedRowPresenter);
- }
- void c1DataGrid1_LoadedRowPresenter(object sender, C1.WPF.DataGrid.DataGridRowEventArgs e)
- {
- e.Row.Presenter.PreviewMouseRightButtonDown += new MouseButtonEventHandler(Presenter_PreviewMouseRightButtonDown);
- }
- void Presenter_PreviewMouseRightButtonDown(object sender, MouseButtonEventArgs e)
- {
- DataGridRowPresenter presenter = sender as DataGridRowPresenter;
- c1DataGrid1.Selection.Add(presenter.Row, presenter.Row);
- }
- private System.Data.DataTable GetData()
- {
- System.Data.DataTable dt = new System.Data.DataTable();
- dt.Columns.Add("ID");
- dt.Columns.Add("Code");
- dt.Columns.Add("Name");
- dt.Rows.Add(1, "A10001", "Name_1");
- dt.Rows.Add(2, "A10002", "Name_2");
- dt.Rows.Add(3, "A10003", "Name_3");
- dt.Rows.Add(4, "A10004", "Name_4");
- dt.Rows.Add(5, "A10005", "Name_5");
- return dt;
- }
- }
复制代码 |