logo
down
shadow

Possible to change cell style when row is clicked WPF DataGrid?


Possible to change cell style when row is clicked WPF DataGrid?

By : deparodo
Date : November 18 2020, 03:01 PM
I wish this help you Instead of changing the style, I used a MultiDataTrigger to show the arrow indicator I want based on what row is selected in the data grid. Whether this is the best solution or not is up for debate, but the row indicator is merely an arrow text character within a grid (rather than a stackpanel) in my cell that shares space with another textbox. Code shown below:
code :
<DataGridTemplateColumn Header="ID" Width="50" CanUserSort="False">
<DataGridTemplateColumn.CellTemplate>
    <DataTemplate>
        <Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
            <Grid.ColumnDefinition Width="*" />
            <Grid.ColumnDefinition Width="*" />
            <TextBox Name="txtID" Text="{Binding ID, UpdateSourceTrigger=PropertyChanged}" MaxLength="20" />
            <TextBox Name="txtArrow" HorizontalAlignment="Stretch">
                <TextBox.Style>
                    <Style TargetType="TextBox" BaseOn="{StaticResource MyTextBoxStyle}">
                        <Style.Triggers>
                            <MultiDataTrigger>
                                <MultiDataTrigger.Conditions>
                                    <Condition Binding="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type DataGridRow}}, Path=IsSelected}" Value="True" /> 
                                </MultiDataTrigger.Conditions>
                                <Setter Property="Text" Value="--&gt;" />
                            </MultiDataTrigger>
                        </Style.Triggers>
                    </Style>
                </TextBox.Style>
            </TextBox>
        </Grid>
    </DataTemplate>
</DataGridTemplateColumn.CellTemplate>


Share : facebook icon twitter icon
Find datagrid column name when a cell is clicked in datagrid

Find datagrid column name when a cell is clicked in datagrid


By : AJW
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , The original source being clicked isn't really connected to the so called item container (see the DataGrid.ItemContainerGenerator) so trying to work yourself up the hiearchy, although a nice idea won't get you to far.
For a quite silly simple solution you could use the knowledge of it being only one cell being clicked and thus using that clicked cell to retrieve the column, as this:
code :
private void DataGrid_PreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
    // First check so that we´ve only got one clicked cell
    if(myGrid.SelectedCells.Count != 1)
        return;

    // Then fetch the column header
    string selectedColumnHeader = (string)myGrid.SelectedCells[0].Column.Header;
}
WPF DataGrid with cell style -- different cell style in same column

WPF DataGrid with cell style -- different cell style in same column


By : Не Могу Без Тебя
Date : March 29 2020, 07:55 AM
To fix this issue I was just wondering how can I assign different cell style for same column? Cell style might be combo box or text box. Image uploaded. Is it really hard? , You could :
How do I change the style of one individual cell in a Flex DataGrid?

How do I change the style of one individual cell in a Flex DataGrid?


By : user3179880
Date : March 29 2020, 07:55 AM
I wish this help you In Flex 3.5 you need a custom itemRenderer.
The way I'd do it is I'd have two states. Normal and "checkbox" and then when you override the data setter in the itemRenderer change your state accordingly.
Change image of a button in a datagrid cell when it is clicked - wpf

Change image of a button in a datagrid cell when it is clicked - wpf


By : lvzitong
Date : March 29 2020, 07:55 AM
wish help you to fix your issue if your IsClosed is just a toggle to know if button was pressed or release then you can achieve this by just using triggers like below:
code :
 <ToggleButton>
     <ToggleButton.Content>
         <Image>
            <Image.Style>
              <Style TargerType="Image">
                <Setter Property="Source" Value="{Binding Path="DataContext.TickImage" RelativeSource="{RelativeSource AncestorType={x:Type UserControl}}"/>
                 <Style.Triggers>
                      <DataTrigger Binding="{Binding IsChecked, RelativeSource="{RelativeSource AncestorType={x:Type ToggleButton}}" Value="true">
                         <Setter Property="Source" Value="{Binding Path="DataContext.CrossImage" RelativeSource="{RelativeSource AncestorType={x:Type UserControl}}"/>
                      </DataTrigger>
                  </Style.Triggers>
                </Style>
             </Image.Style>
            </Image>
          </ToggleButton.Content> 
        </ToggleButton>
How do I change the value of an individual cell in a WPF datagrid when it is double clicked?

How do I change the value of an individual cell in a WPF datagrid when it is double clicked?


By : atunc
Date : March 29 2020, 07:55 AM
like below fixes the issue If you wanna know which DataGridCell is being double-clicked, you must add this to your XAML:
code :
<DataGrid.CellStyle>
    <Style TargetType="DataGridCell">
        <EventSetter Event="MouseDoubleClick" Handler="dataGrid1_CellDoubleClick" />
    </Style>
</DataGrid.CellStyle>
private void dataGrid1_CellDoubleClick(object sender, RoutedEventArgs e)
{
    var cell = sender as DataGridCell;

    // Do stuff with your cell
}
private void dataGrid1_CellDoubleClick(object sender, RoutedEventArgs e)
{
    var cell = sender as DataGridCell;

    if (cell != null && cell.Content is TextBlock)
    {
        var textBlock = cell.Content as TextBlock;
        textBlock.SetCurrentValue(TextBlock.TextProperty, "put your text here");
        var binding = BindingOperations.GetBindingExpression(textBlock, TextBlock.TextProperty);
        binding.UpdateSource();
    }
}
private void dataGrid1_CellDoubleClick(object sender, RoutedEventArgs e)
{
    var cell = sender as DataGridCell;

    if (cell != null)
    {
        (this.DataContext as MyViewModel).DoStuff(cell.DataContext, cell.Column.SortMemberPath);
    }
}
Related Posts Related Posts :
  • How can I get NHibernate to map to a Tuple or Class?
  • MVC 5 C# Window Authentication pop up when I navigate to a certain area
  • Mongo C# driver toJson() DateTime
  • Coprime integers
  • What is the purpose with files ending with *CS.cs in Xamarin Forms projects?
  • MVC5 / Entity | Update/Create Complex Model
  • How to return auto increment ID from SQL using Petapoco ORM in .NET MVC
  • Create new web app offline c# using Visual Studio
  • How many times is ordered the IEnumerable in this case?
  • C# error when update database 2008 to sql 2016
  • How to insert string in multiple continuous pattern in windows c#
  • How to send temp data from Partial View to its parent View
  • C# encapsulation when getting updates from asynchronous method
  • Asp net core Content Security Policy implementation
  • @Html.DropDownList() Placeholder as Disable and Selected
  • Set AM/PM in Material Time Picker WPF
  • Ninject passing reference in constructor
  • C# Entity Framework text SQL query wrapper
  • Core 2.0 MVC - AD Group Authorization for logging
  • Decentralized NLog Target per Http request
  • How to use x:Object and when?
  • Displays file icons in asp.net on GridView
  • How do I avoid two (or more) threads that work on a table at the same time to not work on same row?
  • Add xml attribute for property in DB First
  • How do i execute 2 sql queries by clicking a button [C#]
  • convert jsonstring to objects c#
  • How do request a correct access token in ASP.NET Core for Azure AD to access Microsoft Graph
  • How to run a .NET Core console application on Linux
  • UI not updating for bound element
  • C# Odata v4 open type raw values
  • DocumentFormat.OpenXml Modify Creator Propery of Document
  • How to SetBasePath in ConfigurationBuilder in Core 2.0
  • ASP MVC5 public readonly variable changes value when it should not
  • How to conditionally select item from hashset with queryable linq?
  • Progress Bar C# not showing the real progress
  • Correct logic to reconnect in SignalR with HubConnection
  • ComboBox with two or more sections
  • .NET listbox to SQLite DB
  • C# Ninject binding from Dictionary<Type, Type>
  • asp.net mvc -view displaying real-time progress status
  • Getting reference to dependent in service with generic type
  • Implementing EqualityCompare vs overriding GetHashCode and Equals
  • C# Linq Find all indexes of item in List<int> within another List<int>
  • XML image how to display at data grid columns in c#.net
  • How to override Equals and GetHash of HashSet
  • Creating Windows authentication and SQL Server authentication in login form
  • How to interop with Azure Service Bus topics created by MassTransit using Rebus?
  • MVC 5 Google Calendar Integration
  • C# - Use parallel arrays to calculate cost of a phone call in GUI
  • Use a int in entire code
  • How to display newly added element at the top of StackPanel in WPF?
  • T4MVC is generating T4MVC.cs and T4MVC1.cs
  • Remove blur effect on certain controls inside UserControl
  • Sql Transcation Query to Linq Query in Wcf Rest Service
  • Setting AWS S3 credentials in C# app
  • does not contain in an ObservableCollection
  • App doesn't run it crashed directly after I started it
  • Is it possible in Entity Framework MVC application to run .sql scripts on a different database
  • Type Inference with Deconstruct tuple assignment extension methods
  • Setting up mock objects for EF dbcontext to test repository methods
  • shadow
    Privacy Policy - Terms - Contact Us © voile276.org