Have a visualization issue with DataGrid selection

Socarsky

Well-known member
Joined
Mar 3, 2014
Messages
59
Programming Experience
Beginner
My program Window's grid has a TabControl, and this TabControl has three DataGrid in each TabControl's Item and last thing there is a Label upper side of TabControl to show how many lines of data contain in my text database file.
I use this line of code in Window_Loaded:
DGWProgress.ItemsSource = RetrieveDGWProgress().DefaultView;


As you can see RetrieveDGWProgress returns a DataTable to DataGrid's ItemSource with right numbers of line record in the text file. So far so good. But I want to populate the Label.Content with another returned Method when another TabControl's Item selected. I also thought that I handled this fact with using SelectionChanged Event of TabControl but then my issue occurs. Exactly I cannot click easily DataGrid cells in all of three. It feels like not smoothly clicking cells, not each time but sometimes cells clicking can be done. There is something wrong.
One more thing, if I use the other three DataGrid populating method like I located them in WindowLoaded then everything is fine except Label.Content populating with number of lines in the text file with selection of TabControl. Here are the other lines of code that I can add in WindowLoaded:
DGWLearned.ItemsSource = RetrieveDGWLearned().DefaultView; 
DGWListOfKnowing.ItemsSource = RetrieveDGWListOfKnowing().DefaultView;

And I've tried to use TabControl SelectionChanged event like below:

if (tabctrl.SelectedItem == in_Progress)
{
    DGWProgress.ItemsSource = RetrieveDGWProgress().DefaultView;
}
else if (tabctrl.SelectedItem == learned)
{
    DGWLearned.ItemsSource = RetrieveDGWLearned().DefaultView;
}
else if (tabctrl.SelectedItem == listKnowing)
{
    DGWListOfKnowing.ItemsSource = RetrieveDGWListOfKnowing().DefaultView;
}

If I can populate Label.Content with TabControl selection from
WindowLoaded then would be great but each three populating Method for
DataGrid(s) must works separately when TabControl SelectionChanged.

Here is my XAML:
C#:
<Window x:Name="mainWin" x:Class="VocabBooster.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="504" Width="454" Loaded="Window_Loaded_1" ResizeMode="NoResize">
    <Grid x:Name="mainGrid" Margin="0,0,0,0">
        <TabControl x:Name="tabctrl" HorizontalAlignment="Left" Height="400" Margin="3,64,0,0" VerticalAlignment="Top" Width="433">
            <TabItem x:Name="in_Progress" Header="In Progress">
                <Grid Background="#FFE5E5E5" Margin="0,0,-8,0">
                    <DataGrid x:Name="DGWProgress" DockPanel.Dock ="Top" ItemsSource="{Binding}"  Margin="0,0,10,0" AlternatingRowBackground="LightBlue" AlternationCount="2"/>
                </Grid>
            </TabItem>
            <TabItem x:Name="learned" Header="Learned">
                <Grid Background="#FFE5E5E5">
                    <DataGrid x:Name="DGWLearned" DockPanel.Dock ="Top" ItemsSource="{Binding}"  Margin="0,0,10,0"/>
                </Grid>
            </TabItem>
            <TabItem x:Name="listKnowing" Header="List Of Knowing">
                <Grid Background="#FFE5E5E5">
                    <DataGrid x:Name="DGWListOfKnowing" DockPanel.Dock ="Top" ItemsSource="{Binding}"  Margin="0,0,10,0"/>
                </Grid>
            </TabItem>
        </TabControl>
        <ToolBarTray DockPanel.Dock="Top" Margin="0,0,0,418">
            <ToolBar> 
                <Button x:Name="btnAdd" Click="btnAdd_Click">
                    <StackPanel Orientation="Horizontal">
                        <Image Source="Images/document_new.ico" ToolTip="Add" Width="24"/>
                        <TextBlock Margin="2,5,0,0">Add</TextBlock>
                    </StackPanel>
                </Button>
                <Button x:Name="btnView" Click="btnView_Click">
                    <StackPanel Orientation="Horizontal">
                        <Image Source="Images/magnifier1.ico" ToolTip="View" Width="24"/>
                        <TextBlock Margin="2,5,0,0">View</TextBlock>
                    </StackPanel>
                </Button>
                <Button x:Name="btnDelete" Click="btnDelete_Click">
                    <StackPanel Orientation="Horizontal">
                        <Image Source="Images/delete.ico" ToolTip="Delete" Width="24"></Image>
                        <TextBlock Margin="2,5,0,0">Delete</TextBlock>
                    </StackPanel>
                </Button>
                <Button x:Name="btnTray" Click="btnTray_Click">
                    <StackPanel Orientation="Horizontal">
                        <Image Source="Images/systemtray.ico" ToolTip="Tray" Width="24"></Image>
                        <TextBlock Margin="2,5,0,0">Tray</TextBlock>
                    </StackPanel>
                </Button>
                <Button x:Name="btnSetting" Click="btnSetting_Click">
                    <StackPanel Orientation="Horizontal">
                        <Image Source="Images/setting_3.ico" ToolTip="Setting" Width="24"></Image>
                        <TextBlock Margin="2,5,0,0">Setting</TextBlock>
                    </StackPanel>
                </Button>
                <Button x:Name="btnInfo" Click="btnInfo_Click">
                    <StackPanel Orientation="Horizontal">
                        <Image Source="Images/info.ico" ToolTip="Information" Width="24"></Image>
                        <TextBlock Margin="2,5,0,0">Info</TextBlock>
                    </StackPanel>
                </Button>
                <Button x:Name="btnExit" Click="btnExit_Click">
                    <StackPanel Orientation="Horizontal">
                        <Image Source="Images/exit.ico" ToolTip="Exit" Width="24"></Image>
                        <TextBlock Margin="2,5,0,0">Exit</TextBlock>
                    </StackPanel>
                </Button>
            </ToolBar>
        </ToolBarTray>
        <Label x:Name="lblAnnouncement" HorizontalAlignment="Left" Margin="6,42,0,0" VerticalAlignment="Top" Width="427" Height="27"/>
    </Grid>
</Window>
 
Back
Top Bottom