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

  • SEARCH
  • Home
  • 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 8157133
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T17:10:35+00:00 2026-06-06T17:10:35+00:00

I have a DataGrid in my wpf app <DataGrid Name=datagrid2 ItemSource={Binding} CanUserReorderColumns=False IsReadOnly=True SelectionMode=Single

  • 0

I have a DataGrid in my wpf app

<DataGrid Name="datagrid2" ItemSource="{Binding}" CanUserReorderColumns="False" 
          IsReadOnly="True" SelectionMode="Single" CanUserResizeColumns="False" 
          CanUserResizeRows="False" LoadingRow="datagrid2_LoadingRow" />

and I am providing its ItemSource as

datagrid2.ItemSource = mydatatable.DefaultView;

and its rowheader as

private void datagrid2_LoadingRow(object sender, DataGridRowEventArgs e)
{
    e.Row.Header = Some_string_araay[e.Row.GetIndex()];
}

Sometimes my problem arises that rowheader becomes first column’s data. Hence the last column and its data becomes headerless. I thought it was a layout problem, so after providing ItemSource and in LoadingRow I do datagrid2.UpdateLayout(). But the problem remains the same.

enter image description here

enter image description here

When I click on any ColumnHeader, data gets aligned correctly.

enter image description here

enter image description here

What could be the reason and solution for this problem?

  • 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-06-06T17:10:36+00:00Added an answer on June 6, 2026 at 5:10 pm

    Ok, I think I know why this is happening.

    The first column(having your row headers) width is determined at run-time based on its contents(row header data) when grid loads. Now in your case when grid loads your row headers have no data(you set header in LoadingRow event) so the width of first column gets set to 0; Once you update the row headers it doesn’t get reflected as DataGrid doesn’t refreshes itself.

    Once you click on a column header it recalculates the RowHeader width and this time it is correct as your row headers have data.

    There should be some easy solution to this but one way to do this can be to bind your RowHeaderWidth with the SelectAllButton(in 0,0, cell) like this –

    // Loaded event handler for Datagrid
    private void DataGridLoaded(object sender, RoutedEventArgs e)
    {
        datagrid2.LayoutUpdated += DataGridLayoutUpdated;
    }
    
    private void DataGridLayoutUpdated(object sender, EventArgs e)
    {
        // Find the selectAll button present in grid
        DependencyObject dep = sender as DependencyObject;
    
        // Navigate down the visual tree to the button
        while (!(dep is Button))
        {
            dep = VisualTreeHelper.GetChild(dep, 0);
        }
    
        Button selectAllButton = dep as Button;
    
        // Create & attach a RowHeaderWidth binding to selectAllButton; 
        // used for resizing the first(header) column
        Binding keyBinding = new Binding("RowHeaderWidth");
        keyBinding.Source = datagrid2;
        keyBinding.Mode = BindingMode.OneWay; // Try TwoWay if OneWay doesn't work)
        selectAllButton.SetBinding(WidthProperty, keyBinding);
    
        // We don't need to do it again, Remove the handler
        datagrid2.LayoutUpdated -= DataGridLayoutUpdated;
    }
    

    I have done something similar to change the first column’s widht based on 0,0’th cell data and it works fine; Hope this will work for you.

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

Sidebar

Related Questions

In my wpf app, I have a datagrid as follows <Custom:DataGrid x:Name=dg_nba IsEnabled={Binding Iseditmode}
I have following DataGrid in wpf. <DataGrid AutoGenerateColumns=False Grid.Row=1 Name=adsGrid ItemsSource={Binding Path=Ads} CanUserAddRows=False CanUserDeleteRows=False
I have a DataGrid in WPF app with several columns, including a Name column.
I have a wpf datagrid, Here's my datagrid <dg:DataGrid x:Name=dataGrid AutoGenerateColumns=false ColumnHeaderStyle={StaticResource columnHeaderStyle} AlternationCount=2
I have developed a simple DB-editing app using Xceed's excellent DataGrid for WPF (UX
In my WPF app, I have a datagrid with a IntegerUpDown control displayed in
I have a WPF 4 app with a ComboBox embedded in a DataGrid. The
I have a datagrid from wpf Toolkit, with the itemsource binded to a Observable<Item>
I have a WPF app that uses DataGrid to display some data. When I
I have a Windows Forms app, that has a single ElementHost containing a WPF

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.