Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6926173
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:53:01+00:00 2026-05-27T10:53:01+00:00

I have a datagrid displaying the contents of a custom data type. <DataGrid Name=TestGrid

  • 0

I have a datagrid displaying the contents of a custom data type.

<DataGrid Name="TestGrid" ItemsSource="{Binding Source={StaticResource Data}}" AutoGenerateColumns="False">
  <DataGrid.Columns>
    <DataGridTextColumn Header="Value 1" Binding="{Binding Value1, StringFormat={}{0:C}}"/>
    <DataGridTextColumn Header="Value 2" Binding="{Binding Value2, StringFormat={}{0:#.00}}"/>
  </DataGrid.Columns>

I want to tie different commands to the MouseLeftButtonDown and MouseRightButtonDown events for each DataGridTextColumn. I can use a DataGridTemplateColumn’s CellEditingTemplate to do some customization of input, but haven’t been able to figure out how to get the behavior I want.

Edit: What I’m aiming for is a left click increments the value and a right click decrements it, the size of the +/- would vary column to column.

Edit 2: It seems that you can change styles based on mouse events using triggers, but this doesn’t seem to work for changing the data itself. I’m leaning towards abandoning the datagrid and going with a ListView

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T10:53:02+00:00Added an answer on May 27, 2026 at 10:53 am

    Here are my thoughts on the subject:

    1. You do not seem to need any editing functionality in your dataGrid from what I understand. In this case, you would indeed be better off with a ListView.

    2. If you want to continue with your dataGrid, the easiest way to do would indeed be to use TextBoxColumn.CellStyle and add the event listener there. If you do this, you’ll have to make sure you update the ViewModel’s value in your handler.

    Try sompething like this:

    <DataGrid Name="TestGrid" ItemsSource="{Binding Source={StaticResource Data}}" AutoGenerateColumns="False">
         <DataGrid.Columns>
              <DataGridTextColumn Header="Value 1" Binding="{Binding Value1, StringFormat={}{0:C}}">
                  <DataGridTextColumn.CellStyle>
                       <Style TargetType="DataGridCell">
                            <EventSetter Event="MouseLeftButtonDown" Handler="MyMouseLeftButtonDownHandler" />
                            <EventSetter Event="MouseRightButtonDown" Handler="MyMouseRightButtonDownHandler" />
                        </Style>
                   </DataGridTextColumn.CellStyle>
              </DataGridTextColumn>
              <DataGridTextColumn Header="Value 2" Binding="{Binding Value2, StringFormat={}{0:#.00}}">
                  <DataGridTextColumn.CellStyle>
                       <Style TargetType="DataGridCell">
                            <EventSetter Event="MouseLeftButtonDown" Handler="MyMouseLeftButtonDownHandler" />
                            <EventSetter Event="MouseRightButtonDown" Handler="MyMouseRightButtonDownHandler" />
                       </Style>
                  </DataGridTextColumn.CellStyle>
              </DataGridTextColumn>
         </DataGrid.Columns>
    </DataGrid>
    

    or make your own MyDataGridTextBoxColumn class that inherits the original one, and add the style to the column’s cellStyle in your column’s xaml definition. (that way you have only one common portion of code)

    then in the handlers, you can easily deduce the cell where you clicked and increment or decrement the viewModel accordingly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a DataGrid in my wpf app <DataGrid Name=datagrid2 ItemSource={Binding} CanUserReorderColumns=False IsReadOnly=True SelectionMode=Single
I have datagrid whichs items source is domainDataSource. How i can refresh Domain data
I have a datagrid that is displaying data that is being returned from a
I have a web page displaying data using dojo datagrid. Sometimes, users need to
I have a silverlight datagrid which is bound to a PagedCollectionView displaying a collection
I have a data grid where I am displaying my messages. In that if
I have a DataGrid displaying search info that is created and appended to my
I have a datagrid that displays items with two columns of text row data
I have couple of tasks listed in a datagrid, with their task name and
I have a DataGrid displaying bunch of Objects. Those objects have a property IsDetailsExpanded

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.