2

在网格中,我只需要在同一列中选择多个单元格。不应允许用户从不同列中选择单元格。

我试过下面的代码。

  Private Sub grdTransactions_InitializeLayout(ByVal sender As Object, _ 
    ByVal e As Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs) _ 
    Handles grdTransactions.InitializeLayout
         e.Layout.Override.CellClickAction = Infragistics.Win.UltraWinGrid.CellClickAction.CellSelect
  End Sub

  Private Sub grdTransactions_AfterSelectChange(sender As Object, _ 
     e As AfterSelectChangeEventArgs) Handles grdTransactions.AfterSelectChange

        Me.grdTransactions.DisplayLayout.Override.SelectTypeCell = UltraWinGrid.SelectType.Single
        Me.grdTransactions.DisplayLayout.Override.SelectTypeCol = UltraWinGrid.SelectType.Single

        Me.grdTransactions.DisplayLayout.Bands(0).Override.SelectTypeCell = UltraWinGrid.SelectType.Extended
        Me.grdTransactions.DisplayLayout.Bands(0).Override.SelectTypeCol = UltraWinGrid.SelectType.Single

       Me.grdTransactions.DisplayLayout.Bands(0).Override.MultiCellSelectionMode = MultiCellSelectionMode.Default

      Me.grdTransactions.DisplayLayout.Bands(0).Override.MaxSelectedCells = 100

  End Sub

上面的代码允许从差异列中选择单元格。告诉我我哪里错了?

4

1 回答 1

2

如果您使用的是 ultraGrid1_BeforeSelectChange() 事件,也许解决此任务的一种可能方法是。例如:

 private void ultraGrid1_BeforeSelectChange(object sender, Infragistics.Win.UltraWinGrid.BeforeSelectChangeEventArgs e)
    {
        if (e.NewSelections.Cells.OfType<UltraGridCell>().First().Column.Key != e.NewSelections.Cells.OfType<UltraGridCell>().Last().Column.Key)
        {
            e.Cancel = true;
        }
    }
于 2013-07-31T11:44:49.993 回答