簡體   English   中英

單擊第一個數據網格行不觸發selectedIndex更改

[英]Click on first datagrid row don't trigger selectedIndex change

我有一個數據網格:

<TabControl Grid.Row="3" VerticalAlignment="Stretch" Grid.ColumnSpan="2" VerticalContentAlignment="Stretch" HorizontalContentAlignment="Stretch" HorizontalAlignment="Stretch">
        <TabItem Header="Presentation">
            <DataGrid ItemsSource="{Binding Path=CombinedPresentation , Mode=TwoWay}" 
                      SelectedIndex="{Binding Path=SelectedIndex, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" 
                      AutoGenerateColumns="False" IsReadOnly="True">
                <DataGrid.Columns>
                    <DataGridTextColumn Header="ObjectName" Binding="{Binding ObjectName}"></DataGridTextColumn>
                    <DataGridTextColumn Header="bActivated" Binding="{Binding bActivated}"></DataGridTextColumn>
                </DataGrid.Columns>
            </DataGrid>
        </TabItem>
        <TabItem Header="Presentation Piece" IsEnabled="{Binding Path=PieceEnabled}">
            <DataGrid ItemsSource="{Binding Path=CombinedPresentationPiece , Mode=TwoWay}" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch"/>
        </TabItem>
    </TabControl>

SelectedIndex綁定:

public int SelectedIndex
    {
        get
        {
            return _selectedIndex;
        }
        set
        {
            if (value == -1)
            {
                PieceEnabled = false;
                _selectedIndex = value;
                OnPropertyChanged();
            }
            else
            {
                PieceEnabled = true;
                _selectedIndex = value;
                OnPropertyChanged();
                DoSomeLogic();
            }

        }
    }
    private int _selectedIndex = 0;

並啟用第二個標簽:

private bool _pieceEnabled= false;
    public bool PieceEnabled
    {
        get
        {
            return _pieceEnabled;
        }
        set
        {
            _pieceEnabled = value;
            OnPropertyChanged();
        }
    }

數據網格的數據源

private List<CombinedPresentationDto> _combinedPresentation;
    public List<CombinedPresentationDto> CombinedPresentation
    {
        get
        {
            return _combinedPresentation;
        }
        set
        {
            _combinedPresentation = value;
            OnPropertyChanged();
        }
    }

歸檔數據源:

private void GetPresentation()
    {
        try
        {
            string query = @"Select * from testTable";
            Presentation = dataContext.ExecuteQuery<PresentationDto>(query, new string[] { }).ToList();
            if (Presentation.Count > 0 && GetPresentationPieces())
            {
                CombinedPresentation = PresentationCombiner.CombinePresentations(Presentation, PresentationPiece);
            }
        }
        catch (Exception ex)
        {
        }
    }

PresentationCombiner我只是在Presentation和PresentationPiece之間找到對,並將它們合並為一個對象。

我的問題是,例如Datagrid顯示兩行。 如果用戶選擇行之一,則應啟用第二個選項卡(它顯示連接到所選行的數據)。 但是選擇第一行不會觸發selectedindex 用戶需要選擇第二行然后選擇第一行來觸發選擇第一行

在無法看到用於填充DataGridView的代碼的情況下,我想您已經選擇了第一行,因此單擊它不會更改SelectedIndex。 確保在填充DataGridView之后沒有選擇任何行。

禁用當前單元格選擇

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM