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 3636706
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T01:04:02+00:00 2026-05-19T01:04:02+00:00

I have a DataGrid , which is bound to a DataTable object. The user

  • 0

I have a DataGrid, which is bound to a DataTable object. The user can press a special button, which will dynamically add new columns to this DataTable object. The AutoGenerateFields property in my DataGrid is set to false, because each column in this is styled column with a DataTemplate (each cell contains several TextBlocks).

I wrote the following style for my DataGrid:

<Style TargetType="{x:Type igDP:CellValuePresenter}" x:Key="YPStyle">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type igDP:CellValuePresenter}">
                    <Grid Margin="4" Visibility="{Binding Path=DataItem.YPURL, Converter={StaticResource MyVisiblityConverter}}">
                        <Grid.RowDefinitions>
                            <RowDefinition />
                        </Grid.RowDefinitions>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition />
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition Width="Auto"/>
                        </Grid.ColumnDefinitions>
                        <TextBlock Grid.Row="0" Grid.RowSpan="2" Grid.Column="0"
                                           FontWeight="DemiBold"
                                           FontSize="18"
                                           VerticalAlignment="Center"
                                           Text="{Binding Path=DataItem.LYP}" x:Name="c"/>
                        <TextBlock Grid.Row="0" Grid.Column="1"
                                           Foreground="{Binding Path=DataItem.RYP, Converter={StaticResource MyColorConverter}}"
                                           Text="{Binding Path=DataItem.RYP}"
                                           Margin="3, 0, 0, 0"
                                           HorizontalAlignment="Right"
                                           VerticalAlignment="Center"/>
                        <StackPanel Orientation="Horizontal" VerticalAlignment="Center"
                                            Grid.Row="0" Grid.Column="2"
                                            HorizontalAlignment="Right"
                                            Margin="8, 0, 0, 0">
                            <Image Source="../icons/icon_url.gif"
                                           Cursor="Hand"/>
                            <Label Content="url"
                                           Foreground="Blue"
                                           Cursor="Hand"
                                           ToolTip="{Binding Path=DataItem.YPU}"/>
                        </StackPanel>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

You can see, that the TextBlocks are bound to some columns in DataTable: DataItem.LYP, DataItem.YPU.

The problem is finding a dynamic way to set that binding. When the user adds new columns to a bound DataTable object, I creates a new column in my DataGrid with this style. But how can I dynamically set different values for Text properties for my TextBlock in this style?

For example, first column in my DataGrid is bound to Column_1, Column_2, Column_3 in DataTable. When the user presses “Add new column”, program creates 3 new columns in the DataTable object with names “Column_4”, “Column5″, Column 6” and creates new column in the DataGrid with this style. But how can I set binding for second column to new columns in the DataTable?

Thanks a lot.

  • 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-19T01:04:02+00:00Added an answer on May 19, 2026 at 1:04 am

    Now I use style wich was creating in code behind. It’s working!
    Thanks all.

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

Sidebar

Related Questions

I have a DataGrid which is being bound dynamically to a database query. The
I have a datagrid which is populated with CSV data when the user drag/drops
Scenario I have a DevExpress DataGrid which is bound to a DataSet in C#.
I have a DataGrid which is bound to a PagedCollectionView and the underlying collection
I have a wpf datagrid which is bound to an observable collection. Currently I
I have a silverlight datagrid which is bound to a PagedCollectionView displaying a collection
I have a View that displays a DataGrid which is bound to an ObservableCollection
in .net I have created an excel report which takes a datagrid's render output
I have a datagrid getting bound to a dataset, and I want to display
I have a datagrid, populated as shown below. When the user clicks on a

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.