Click here to Skip to main content
15,035,283 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello All,

I have work in inventory application Thats why i am design data grid with editable header section so i want to
IsEnable false


How to disable datagrid row details section  


<DataGrid x:Name="grdproductdetails" AreRowDetailsFrozen="True"   AutoGenerateColumns="False"
                    CanUserResizeRows="False"   ItemsSource="{Binding}"
                    CanUserAddRows="False" Margin="0,0,0,0"   HorizontalGridLinesBrush="#FF020202"  >

                          <DataGrid.Resources>
                              <Style TargetType="DataGridRow" x:Name="grddatagriddetails">
                                  <EventSetter Event="PreviewKeyDown" Handler="grdproductdetails_PreviewKeyDown" />
                                  <EventSetter Event="LostFocus" Handler="grdproductdetails_LostFocus" />
                                  <!--<Setter Property="IsEnabled" Value="False" />-->
                              </Style>
                              <Style TargetType="DataGridColumnHeadersPresenter">
                                  <EventSetter Event="PreviewKeyDown" Handler="grdproductheader_PreviewKeyDown" />
                              </Style>

                          </DataGrid.Resources>


                          <DataGrid.Columns >

                              <DataGridTextColumn      IsReadOnly="False" Width="2.5*"  Header="Product Name" Binding="{Binding mstprd_name}"  FontWeight="Bold"  Foreground="Black"   x:Name="grdtxtproductname"  Visibility="Visible"  >
                                  <DataGridTextColumn.HeaderStyle >
                                      <Style TargetType="DataGridColumnHeader" >
                                          <Setter Property="Template">
                                              <Setter.Value>
                                                  <ControlTemplate TargetType="{x:Type DataGridColumnHeader}">
                                                      <Border BorderBrush="Green" BorderThickness="0 0 0 1">
                                                          <StackPanel Margin="2 1 0 1">
                                                              <Border  BorderThickness="0 0 0 1" BorderBrush="Green" Margin="0 0 0 0">
                                                                  <TextBlock Text="{TemplateBinding Content}" FontWeight="Medium" HorizontalAlignment="Center" Foreground="Black"  Background="WhiteSmoke"/>
                                                              </Border>
                                                              <controls:AutoCompleteTextBox x:Name="TxtProductName" FontWeight="SemiBold"
                                                               Margin="0 5 0 0" FontSize="13"
                                                               Grid.Column="1"
                                                          Grid.Row="0" Grid.ColumnSpan="3"
                                                          materialDesign:HintAssist.Hint="Select Product Name"
                                                          AutoCompleteWidth="900"
                                                          AutoCompleteHeight="200"
                                                          AutoCompletePlacementTarget="{Binding ElementName=txt}"
                                                          AutoCompletePlacement="Bottom"
                                                          OnTextChange="TxtProductName_OnTextChange"
                                                          OnSelectedItemChange="TxtProductName_OnSelectedItemChange"
                                                           PreviewKeyDown="TxtProductName_PreviewKeyDown"
                                                          GotFocus="Ctrlautobox_GotFocus" >
                                                                  <controls:AutoCompleteTextBox.AutoCompleteColumns>
                                                                      <DataGridTextColumn Header="Product Name" MinWidth="100" Width="Auto" Foreground="Black" FontWeight="Medium"  >
                                                                          <DataGridTextColumn.Binding>
                                                                              <MultiBinding StringFormat="{}{0} - {1} - [{2}] - [{3}]">
                                                                                  <Binding Path="mstprd_name" />
                                                                                  <Binding Path="mstprd_shrtname" />
                                                                                  <Binding Path="mstpacking_displaypacking" />
                                                                                  <Binding Path="ProductLocation" />

                                                                              </MultiBinding>
                                                                          </DataGridTextColumn.Binding>
                                                                          <DataGridTextColumn.EditingElementStyle>
                                                                              <Style TargetType="TextBox">

                                                                                  <Setter Property="AcceptsReturn" Value="true" />
                                                                              </Style>
                                                                          </DataGridTextColumn.EditingElementStyle>
                                                                      </DataGridTextColumn>
                                                                      <DataGridTextColumn Header="GST" MinWidth="50" Width="Auto" Foreground="Black" FontWeight="Medium" >
                                                                          <DataGridTextColumn.Binding>
                                                                              <MultiBinding StringFormat="{}{0}">
                                                                                  <Binding Path="prdtax_value" />
                                                                              </MultiBinding>
                                                                          </DataGridTextColumn.Binding>
                                                                      </DataGridTextColumn>
                                                                      <DataGridTextColumn Header="Drug Type" Width="120" Foreground="Black" FontWeight="Medium"  >
                                                                          <DataGridTextColumn.Binding>
                                                                              <MultiBinding StringFormat="{}{0}">
                                                                                  <Binding Path="drugType" />
                                                                              </MultiBinding>
                                                                          </DataGridTextColumn.Binding>
                                                                      </DataGridTextColumn>
                                                                      <DataGridTextColumn Header="Product Type" Width="120" Foreground="Black" FontWeight="Medium" >
                                                                          <DataGridTextColumn.Binding>
                                                                              <MultiBinding StringFormat="{}{0}">
                                                                                  <Binding Path="ProductType" />
                                                                              </MultiBinding>
                                                                          </DataGridTextColumn.Binding>

                                                                      </DataGridTextColumn>
                                                                      <DataGridTextColumn Header="Stock" Width="100" Foreground="Black" FontWeight="Medium" >
                                                                          <DataGridTextColumn.Binding>
                                                                              <MultiBinding StringFormat="{}{0}">
                                                                                  <Binding Path="0"    />
                                                                              </MultiBinding>
                                                                          </DataGridTextColumn.Binding>

                                                                      </DataGridTextColumn>
                                                                      <DataGridTextColumn Header="Agency Name" Width="100" Foreground="Black" FontWeight="Medium" >
                                                                          <DataGridTextColumn.Binding>
                                                                              <MultiBinding StringFormat="{}{0}">
                                                                                  <Binding Path="0"/>
                                                                              </MultiBinding>
                                                                          </DataGridTextColumn.Binding>

                                                                      </DataGridTextColumn>
                                                                  </controls:AutoCompleteTextBox.AutoCompleteColumns>
                                                              </controls:AutoCompleteTextBox>
                                                          </StackPanel>
                                                      </Border>
                                                  </ControlTemplate>

                                              </Setter.Value>
                                          </Setter>
                                      </Style>
                                  </DataGridTextColumn.HeaderStyle>

                              </DataGridTextColumn>





What I have tried:

DataGridRow dgrow = (DataGridRow)grdproductdetails.ItemsSource;
                    dgrow.IsEnabled = false;

i try but not work properly
Posted
Comments
Gerry Schmitz 13-Jun-21 11:38am
   
ItemSource is a "collection"; not some instance of a DataGridRow.
Member 8735045 14-Jun-21 6:13am
   
thanks for replay ,
i have create inventory application , which one is best control for crud operation in wpf to replace datagrid

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900