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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:55:59+00:00 2026-05-26T10:55:59+00:00

Given the following xaml code, I would like to create this xaml code the

  • 0

Given the following xaml code, I would like to create this xaml code the GridView part in C# in order to attach the datasource to the ListView ItemItemsSource
EditBox is just a textbox class

 <ListView.View>
  <!-- Here is the part i'd like to do with C# -->
    <GridView AllowsColumnReorder="true"
              ColumnHeaderToolTip="Employee Information">
      <GridViewColumn DisplayMemberBinding=
                            "{Binding Path=FirstName}" 
                      Header="First Name" Width="100"/>

                <GridViewColumn Header="Last Name" Width="100" >
                    <GridViewColumn.CellTemplate>
                        <DataTemplate>
                            <l:EditBox Height="25" Value="{Binding Path=LastName}" />
                        </DataTemplate>
                    </GridViewColumn.CellTemplate>
                </GridViewColumn>
                <GridViewColumn Header="ID" Width="75" >
        <GridViewColumn.CellTemplate>
          <DataTemplate>
            <l:EditBox Height="25" Value="{Binding Path=EmployeeNumber}" />
          </DataTemplate>
        </GridViewColumn.CellTemplate>
      </GridViewColumn>
     </GridView>
  </ListView.View>
</ListView>

i did something similar in another project.

        ListView ctrl = (ListView)GetCtrl((string)strctrl);//Rebuild the gridview
        ctrl.View = null;
        GridView grid = new System.Windows.Controls.GridView();

        int c = 0;
        foreach (DataColumn lv_col in data.Table.Columns)
        {
            //Skip columns ending with "_ID"
            int ilen = lv_col.ColumnName.Length;
            if (lv_col.ColumnName.Substring(ilen - 3) != "_ID" && lv_col.ColumnName != "Deleted")
            {
                GridViewColumn col = new System.Windows.Controls.GridViewColumn();
                if (labels != null && labels.Contains(lv_col.ColumnName))
                    lv_col.Caption = labels[lv_col.ColumnName].ToString();
                col.Header = lv_col.Caption;
                Binding colbind = new Binding("[" + c.ToString() + "]");

                if (lv_col.DataType.GetType() == typeof(System.DateTime))
                {
                    colbind.StringFormat = date_format;
                    if (Global.Lng == "F") colbind.ConverterCulture = System.Globalization.CultureInfo.CreateSpecificCulture("fr-FR");  // #Even on a engrish system, this should display french dates
                }
                else if (lv_col.DataType.GetType() == typeof(System.Double))
                    colbind.StringFormat = "0";

                col.DisplayMemberBinding = colbind;
                grid.Columns.Add(col);
            }
            c += 1;
        }

        //Restore column widths
        foreach (int i in Enumerable.Range(0, col_widths.Count))
            if (i < grid.Columns.Count) grid.Columns[i].Width = col_widths[i];

        ctrl.View = grid;
        ctrl.ItemsSource = data;

        ctrl.UpdateLayout();//This will force the listview to finish displaying.
  • 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-26T10:56:00+00:00Added an answer on May 26, 2026 at 10:56 am

    I’m not sure what part you are having trouble with but I suspect it’s with the DataTemplates. I don’t know what your EditBox is so I just used a TextBox.

            var gridView = new GridView { AllowsColumnReorder = true, ColumnHeaderToolTip = "Employee Information" };
    
            // column 1
            var col1 = new GridViewColumn { DisplayMemberBinding = new Binding("FirstName"), Header="First Name", Width=100 };
            gridView.Columns.Add(col1);
    
            // column 2 
            var col2 = new GridViewColumn { Header="Last Name", Width=100 };
            var fef2 = new FrameworkElementFactory(typeof(TextBox));
            fef2.SetValue(TextBox.HeightProperty, 25d);
            fef2.SetBinding(TextBox.TextProperty, new Binding("LastName"));
            col2.CellTemplate = new DataTemplate { VisualTree = fef2 };
            gridView.Columns.Add(col2);
    
            // column 3
            var col3 = new GridViewColumn { Header = "ID", Width = 75 };
            var fef3 = new FrameworkElementFactory(typeof(TextBox));
            fef3.SetValue(TextBox.HeightProperty, 25d);
            fef3.SetBinding(TextBox.TextProperty, new Binding("EmployeeNumber"));
            col3.CellTemplate = new DataTemplate { VisualTree = fef3 };
            gridView.Columns.Add(col3);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given the following XAML code that with a ListControl like behavior: <StackPanel> <ItemsControl Name=_listbox
The following code is part of a small XAML application that displays data in
Given the following XAML markup, I would expect the text in the Hyperlink to
Given the following code why would My Stupid Text never be bound to the
Given the following code: <Window x:Class=WpfApplication76.Window1 xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml xmlns:col=clr-namespace:System.Collections;assembly=mscorlib Title=Window1 Height=300 Width=300> <Window.Resources> <CollectionViewSource
given the following XAML code: <Canvas Name=MainView> <Canvas Name=TriangleElement Width=50 Height=50 Canvas.Left=110 Canvas.Top=100> <Canvas.RenderTransform>
Given the following: List<List<Option>> optionLists; what would be a quick way to determine the
Given the following: &row->count Would &(row->count) be evaluated or (&row)->count be evaluated in C++?
Given the following code (that doesn't work): while True: # Snip: print out current
Given the following code: <MenuItem x:Name=MenuItem_Root Header=Root> <MenuItem x:Name=MenuItem_Item1 IsCheckable=True Header=item1 /> <MenuItem x:Name=MenuItem_Item2

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.