logo
down
shadow

WPF DataGrid disable cell edit based on value


WPF DataGrid disable cell edit based on value

By : user2187872
Date : November 28 2020, 04:01 AM
This might help you You need EditingElementStyle to mark the field enabled/disabled
Code below shows how to do it
code :
<DataGridTextColumn Header="Nummer" Binding="{Binding Number}" CanUserSort="False" IsReadOnly="False">
    <DataGridTextColumn.EditingElementStyle>
        <Style TargetType="{x:Type TextBox}">
            <Style.Triggers>
                <DataTrigger Binding="{Binding Number}" Value="">
                    <Setter Property="IsEnabled" Value="False" />
                </DataTrigger>
                <DataTrigger Binding="{Binding Number}" Value="{x:Null}">
                    <Setter Property="IsEnabled" Value="False" />
                </DataTrigger>
            </Style.Triggers>
        </Style>
    </DataGridTextColumn.EditingElementStyle>
</DataGridTextColumn>


Share : facebook icon twitter icon
Disable row edit on WPF DataGrid

Disable row edit on WPF DataGrid


By : Kaiwan Othman
Date : March 29 2020, 07:55 AM
this one helps. I need help here. I'm trying to disable some rows edit on a WPF DataGrid. This is my XAML: , You could define your columns manually
code :
<DataGridTemplateColumn>
   <DataGridTemplateColumn.CellTemplate>
       <DataTemplate>
           <TextBox Text="{Binding Path=YourField}" 
                    IsReadOnly="{Binding IsReadonly}"/>
       </DataTemplate>
   </DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
WPF Datagrid: based on checkbox condition disable another cell in a row for all the rows

WPF Datagrid: based on checkbox condition disable another cell in a row for all the rows


By : Fangerang
Date : March 29 2020, 07:55 AM
I hope this helps . Use a Grid to enforce disabled behavior. If MaxAddToLabelReached property is false, column will be disabled and vice-versa.
Make sure , you either use a converter, or make MaxAddToLabelReached property behave w.r.t code below.
code :
<DataGridTemplateColumn Header="DisplayName" >
    <DataGridTemplateColumn.CellTemplate>
        <DataTemplate>
            <Grid IsEnabled="{Binding MaxAddToLabelReached}">
                <TextBox x:Name="DisplayName" Text="{Binding DisplayName}" />
            </Grid>
        </DataTemplate>
    </DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
  <DataGridTemplateColumn>
       <DataGridTemplateColumn.CellTemplate>
            <DataTemplate>
               <CheckBox Checked="CheckBox_Checked" Unchecked="CheckBox_Unchecked"/>
             </DataTemplate>
       </DataGridTemplateColumn.CellTemplate>
   </DataGridTemplateColumn>
private void CheckBox_Checked(object sender, RoutedEventArgs e)
        {
            /* apply your own condition here */

            Dgrd.Columns[0].IsReadOnly = true; // disable the entire column of all rows

            // to disable only the corresponding cell of the desired column
            CheckBox chk = (CheckBox)sender;
            DataGridRow row = (DataGridRow)Dgrd.ItemContainerGenerator.ContainerFromItem(chk.DataContext);
            DataGridCell p = (DataGridCell) ((TextBlock)Dgrd.Columns[0].GetCellContent(row)).Parent;
            p.IsEnabled = false;
        }

        private void CheckBox_Unchecked(object sender, RoutedEventArgs e)
        {
            /* apply your own condition here */

            // exact opposite of Checked event handler

            Dgrd.Columns[0].IsReadOnly = false; 

            CheckBox chk = (CheckBox)sender;
            DataGridRow row = (DataGridRow)Dgrd.ItemContainerGenerator.ContainerFromItem(chk.DataContext);
            DataGridCell p = (DataGridCell)((TextBlock)Dgrd.Columns[0].GetCellContent(row)).Parent;
            p.IsEnabled = true;
        }
wpf DataGrid disable cell edit for specific row except first column

wpf DataGrid disable cell edit for specific row except first column


By : yang
Date : March 29 2020, 07:55 AM
around this issue I have a binding to a generic DataTable where some rows may contain problems and should not be modified. There seems to be a very easy way to accomplish that by simple setting IsEnabled in DataGrid_LoadingRow or by a Trigger with Binding in XAML. However, I also have a “Info”-Column which has a Button in it so that the user can view the problem… Setting IsEnabled to false also disables my button… I already tried: IsManipulationEnabled but this has no effect. How can I accomplish this? Is the only way for doing that by traversing the VisualTree of the DataRowView and set IsEnabled for all Cells except the first? , For your first column, use this Button,
code :
public class EnabledButton : Button
{
    static EnabledButton()
    {
        UIElement.IsEnabledProperty.OverrideMetadata(typeof(EnabledButton),
                new FrameworkPropertyMetadata(true, FrameworkPropertyMetadataOptions.None,
                    UIElement.IsEnabledProperty.DefaultMetadata.PropertyChangedCallback,
                    new CoerceValueCallback(IsEnabledCoerceCallback)));
    }

    private static object IsEnabledCoerceCallback(DependencyObject d, object baseValue)
    {
        return (bool)baseValue;
    }
}
<DataGrid.Columns>
    <DataGridTemplateColumn>
        <DataGridTemplateColumn.CellTemplate>
            <DataTemplate>
                <local:EnabledButton IsEnabled="True" Content="Modify"/>
            </DataTemplate>
        </DataGridTemplateColumn.CellTemplate>
    </DataGridTemplateColumn>
    ...
</DataGrid.Columns>
ag-grid : Disable cell edit on key press and pro grammatically enable row edit with edit button (Angular 2)

ag-grid : Disable cell edit on key press and pro grammatically enable row edit with edit button (Angular 2)


By : Cherman
Date : March 29 2020, 07:55 AM
this will help While defining the columnDefs , give editable: false
On clicking the edit button, for dynamically editing the particular Column/Cell in row use:
code :
this.GridOptions.columnApi.getColumn('employeeName').getColDef().editable = true;
 this.GridOptions.columnApi.getColumn('employeeName').getColDef().editable = false;
disable a button from datagrid view based on a column in datagrid c# wpf

disable a button from datagrid view based on a column in datagrid c# wpf


By : Jon
Date : March 29 2020, 07:55 AM
To fix the issue you can do You can try using DataTemplate Triggers and set needed property inside it. For example, if Availability is a property in DataContext of DataTemplateColumn, it will look nearly like this:
code :
<DataGridTemplateColumn.CellTemplate>
  <DataTemplate>
     <Button x:Name="deployBtn" Click="deployBtn_Click" Height="25" Width="45" Background="#FF43B46C"  Margin="0 -3 0 0">
     //...your code
     </Button>
  <DataTemplate.Triggers> 
     <DataTrigger Binding="{Binding DataContext.Availability RelativeSource={RelativeSource AncestorType=DataTemplateColumn}}" Value="Unavailable">
        <Setter Property="IsEnabled" TargetName="deployBtn" Value="False"/>
     </DataTrigger>
  </DataTemplate.Triggers>
  </DataTemplate>
Related Posts Related Posts :
  • Linq to object Multiple Where short circuit evaluation
  • WPF - Create solid layout without designer
  • View not rendering on NET Core
  • Proper way to create domain models and viewmodels in microservices
  • StaticInjectorError(AppModule)[AuthGuard] after login
  • Getting Entity Model dynamically based on TableName?
  • Customizing the Navigation Form after my form's confirmation dialog
  • CSHTML Confirm Delete prior to deleting database record
  • How to set property values for indexers using Expressions?
  • My Mandelbrot sketching program in c# isn't working
  • Best way to validate a date string in C#
  • Bot Framework v4 Bot emulator authentication bad request
  • Can I use MVC 5 remote validation to check for duplicate values, but exclude the item being edited?
  • How to get list of all databases using MongodbClient class. (C# application)
  • how to check if there are 4 or more spaces in streamread line
  • How to perform style changes on datagridview rows using rows from the underlying bindingsource?
  • How do I add a C# solution file in Jetbrains Rider?
  • Docker ASP.NET CORE 2.1 app in Visual Studio 2017. App does not start in debug mode
  • ASP.NET Core WebApi with SQL Server and EFCore 2
  • Sitefinity Widget User Control
  • MultiSelectList shows one value from the IEnumerable given to it with multiple values
  • Items in picker from a list - Xamarin Code behind
  • How can I insert/update a List<T> as member of an entity in SQLite?
  • How to "flush" ApplicationInsightsTraceListener, in a Console Application, on exit?
  • Named Pipes Between Winforms and Service Can Only Connect Once
  • Add CDATA to a Node Value in a loop
  • Custom serializer for just one property in Json.NET, without changing the model class
  • How to stop a timer/change system UI OnSleep Xamarin Android
  • LINQ parse xml file and get values from specific nodes
  • How do I set the time out for page load?
  • Clarification of IL generated code referenced to strings
  • EntityFrameworkCore.SQLLite and UWP Not behaving as expected
  • WPF MediaElement: Video opened twice
  • Temporary excel file with Interop library
  • Insert \u2265 into a C# string
  • Constant Enemy Damage to Player - Unity 2019.1 Beta
  • Is there a way to scan for viruses when downloading an attachment using EWS?
  • How to generify a method when T can be multiple new () Types?
  • Reading binary file data into List of Structs
  • Updating Status Strip on Form from BackgroundWorker
  • Visual Studio using GIT repository Publishing with API and Website in one Solution
  • Return Standard Deviation of column values with other column value condition LINQ
  • Grab a count of different values in object
  • c# File used by who?
  • How to parse string into an array using set number of characters in C#
  • How to sent list using CommandParameter
  • Problem with referencing ResourceDictionaries, and Styling across multiple assemblies
  • StackExchange Redis - high CPU usage on WriteAllQueues
  • Not typing the full variable name but partial name is represented by another string value
  • Linq to Entities Selecting Data with Max Date?
  • How to extract data using Ical.Net?
  • C# program crashes because listbox items change
  • Kicking a user in Discord.Net
  • C# Linq Find duplicates with multiple group by
  • How to call control on a Panel that is inside usercontrol
  • c# ReadAsJsonAsync in framework 4.5
  • Inner join two table variables and return an output cursor from an anonymous plsql block in a c# application
  • Notify consumers when all tasks have completed without blocking the thread
  • Replace "\\" with "\" in a path
  • CSS Not formatting inside repeater
  • shadow
    Privacy Policy - Terms - Contact Us © bighow.org