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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:42:57+00:00 2026-05-27T21:42:57+00:00

I am creating a DataGridTemplateColumn dynamically in my application. The reason for this, is

  • 0

I am creating a DataGridTemplateColumn dynamically in my application. The reason for this, is because I have a TabControl and when the user wants to add a new Tab, a Datagrid is created in the TabItem. Here is the code that I have so far to create my column:

    private DataGridTemplateColumn GetAccountColumn()
    {
        DataGridTemplateColumn accountColumn = new DataGridTemplateColumn();
        accountColumn.Header = "Account";

        string xaml = @"<DataTemplate xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"">
                            <TextBlock Text=""{Binding Path='Account', Mode=OneWay}"" />
                        </DataTemplate>";

        StringReader stringReader = new StringReader(xaml);
        XmlReader xmlReader = XmlReader.Create(stringReader);

        accountColumn.CellTemplate = (DataTemplate)XamlReader.Parse(xaml);

        xaml = @"<DataTemplate xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"">
                     <ComboBox ItemsSource=""{DynamicResource accounts}"" Text=""{Binding Path='Account', Mode=OneWay}"" Height=""23"" IsTextSearchEnabled=""True""/>
                 </DataTemplate>";

        stringReader = new StringReader(xaml);
        xmlReader = XmlReader.Create(stringReader);

        accountColumn.CellEditingTemplate = (DataTemplate)XamlReader.Parse(xaml);

        return accountColumn;
    }

The combobox is populated with items perfectly. As you can see from the code above, the itemsource is bound to an observable collection of strings. I populate the resource during runtime by the following:

Resources["accounts"] = this.Account;

Everything seems to work nicely, EXCEPT after I make a selection in the combobox and the combobox loses focus, the item I selected is not displayed in the TextBlock. How can I make this item appear in the TextBlock? I tried setting the mode to TwoWay but I get an error saying “A TwoWay or OneWayToSource binding cannot work on the read-only property ‘Account’ of type ‘System.Data.DataRowView’.”

  • 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-27T21:42:58+00:00Added an answer on May 27, 2026 at 9:42 pm

    You need to bind the SelectedItem property of your ComboBox to Account and not the Text property:

     xaml = @"<DataTemplate xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"">
                     <ComboBox ItemsSource=""{DynamicResource accounts}"" SelectedItem=""{Binding Path='Account'}"" Height=""23"" IsTextSearchEnabled=""True""/>
                 </DataTemplate>";
    

    Edit

    Another problem is this:

    I tried setting the mode to TwoWay but I get an error saying “A TwoWay or OneWayToSource binding cannot work on the read-only property ‘Account’ of type ‘System.Data.DataRowView’.”

    If the Account property is readonly you can’t change it then editing it makes no sense at all. You need to make it writable otherwise you can’t change it from the UI and you can’t store any data.

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

Sidebar

Related Questions

When creating a web application, and lets say you have a User object denoting
Creating a simple blog application, I have this partial .comment %p %b Namn: =
I have a dynamic Datagrid that I have created. I am creating each column
Creating a voting system just like stackoverflow. Questions like this have been asking several
Creating Traversals for Binary Search Tree with Recursion. void inOrder(void (*inOrderPtr)(T&)) { if(this->left !=
Creating a google map with store locations within 50 miles of user entered address.
(creating a separate question after comments on this: Javascript redeclared global variable overrides old
Creating a JApplet I have 2 Text Fields, a button and a Text Area.
Creating an installer for possible remote systems so that if they do not have
Creating a table without tbody using javascript createElement/appendChild will not add tbody in Firebug

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.