.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

How to bind datagrid columns to external (main) datacontext?

Posted By:      Posted Date: September 22, 2010    Points: 0   Category :WPF


I have a datagrid and his columns binds well to its collection data. But when I add a new data column (ie. DataGridTextColumn or DataGridComboBoxColumn) and Bind to the main Data Context of window the data are missing (dont show)

In this sample, The last two columns of DataGrid dont bind to the main data.

<Window x:Class="MainWindow"





View Complete Post

More Related Resource Links

How add and bind DataGrid columns programmatically ??


Hi all,


How are you ??


please i need to know how to add and bind DataGrid columns programmatically ( NOT IN XAML),

i was using  this code in windowsForms i need equivalent for it in WPF please :

            DataGridViewColumn column = new DataGridViewTextBoxColumn();
            column.DataPropertyName = "DataPropertyName";
            column.Name = "columnName";
            column.DisplayIndex = 1;
            column.Width = 150;
            column.ReadOnly = true;
            column.Visible = true;


help me please , Thanks a lot .....






I declared a datagrid in xaml, now I want to add main columns in this datagrid at runtime through vi


I have declared datagrid in xaml like this ;

<DataGrid AutoGenerateColumns="False" ........


and want to access this datagrid in viewmodel to add columns with headers to this datagrid at runtime. Actually i want to declare any number of columns in grid which i read from database table at execution time. If anybody could help me in this regard....


the database result is as follows DATE     code   class1 class2  class3 1/8/10     M1     10       20     30     3/8/10     V2      20       30     10      1/8/10      H1      1           2      3         7/8/10     ! ! 8/8/10     !M2    5      5      5       3/8/10     B2      4      4     4       1/8/10     V1      3      7     3       THE OUTPUT SHOULD BE AS FOLLOWS:- DATE           M1                          M2           

How to Bind Selective Columns from Stored Proc to Gridview using the entity framework


Hi Guys,

I have this entity model>> http://img840.imageshack.us/img840/306/schemaj.jpg and I would like to bind  a list  which consists of: employee's

  • emloyee_firstname(employees table) + employee_lastname(employees table)
  • employee's extension(employee_extension table)
  • deparment name(departments table)

to my gridview. I already created my stored procedure

    Concat(employees.employee_firstname," ",employees.employee_lastname) as name
    , extensions.extension_number
    , departments.department_description
    INNER JOIN employees 
        ON (employee_extensions.employee_id = employees.employee_id)
    INNER JOIN extensions 
        ON (employee_extensions.extension_id = extensions.extension_id)
    INNER JOIN departments 
        ON (employees.department_id = departments.department_id)

But my problem is, i don't know how to bind it since i don't have an entity that contains the employee's name, extension# and departments name. Do I need to create a custom class that consists of said columns? or is their a proper way to do this? I'

Sort WPF Datagrid using multiple columns



Is it possible to sort a WPF datagrid using more than one column ?



I need help please : how do i bind dataGrid to dataTable Programmatically ?


Hi all,


please i need to know if i could  bind dataGrid to dataTable Programmatically using wpf V.S 2010 (without using Xaml code)???


i google it before but i saw solution using (DataSet) and this not useful for me because its huge application.

Note : data source is MySql.


Thanks a lot .


Abed Salem

how to hide a column in a datagrid but autogenerated columns = "True"?



  Anybody help me please!!! I've 3 datasets named ds1, ds2, ds3. Then i merged that 3 datasets into 1 datatable named dt1. Now, my question is, i want to hide some datacolumns its present in an ds2. How????? Below i attached my code,



connectionString = "provider=MSDAORA;data source=proact;user id=mah;password=mah";


OleDbConnection myOleDbConnection = new OleDbConnection(connectionString);


Datagrid with varying columns


I am upgrading a classic asp page, the page uses response.write to make a table, as soon as a null value comes up for a month the columns of the grid then stop.  The sql is below

SELECT sName, Strategy, 
Sum(case when Month([Date])=1 then Rtn else null end) as Jan, 
Sum(case when Month([Date])=2 then Rtn else null end) as Feb, 
Sum(case when Month([Date])=3 then Rtn else null end) as Mar, 
Sum(case when Month([Date])=4 then Rtn else null end) as Apr, 
Sum(case when Month([Date])=5 then Rtn else null end) as May, 
Sum(case when Month([Date])=6 then Rtn else null end) as Jun, 
Sum(case when Month([Date])=7 then Rtn else null end) as Jul, 
Sum(case when Month([Date])=8 then Rtn else null end) as Aug, 
Sum(case when Month([Date])=9 then Rtn else null end) as Sep, 
Sum(case when Month([Date])=10 then Rtn else null end) as Oct, 
Sum(case when Month([Date])=11 then Rtn else null end) as Nov, 
Sum(case when Month([Date])=12 then Rtn else null end) as Dec  
FROM Chess

If this is run in oct i only have data from jan -0ct , how do i not display nov and dec so that its dynamic?

Group by on external data columns



I created an external content type "Auction" from a SQL table. I added an external data column "Auction" to my document library and selected a few fields to be shown as additional information on "Auction". I would like to create a view where the documents are grouped by one of those additional fields, but the field I need is not shown in the view settings... Is it possible to sort/group on the additional columns comming from from my external data column?





Sorting or Grouping by "External Data" columns secondary fields - only possible for certain value ty


I have a BCS connection to an external system that provides various external data types.

I'm now adding an "External Data" column to a SharePoint list, selecting multiple fields of an external data type to be added as list columns. These fields have different data types, in my case string, DataTime and Boolean.

Editing the list view settings, I can only select the external entity as a whole, or it's Boolean fields for either "Sort By" or "Group By". The other fields are not offered for selection.

Is there any restrictions on which secondary fields of an external data type are supported for either sorting or grouping? Or is there something wrong in the definition of some of the external data type fields?

Thanks in advance for any help on this issue...

Bind ComboBox in DataGrid row



I want to bind ComboBox to database table (via ADO.NET Entity Framework) and put it in DataGrid. Now I have DataGrid with binded TextBlock, but when I try to bind ComboBox it doesn't work.


I have table with list if countries and table users, where each user has foreign key of country where he lives.

I want to show in DataGrid user details like:

Alex Gorr     Canada     al.gorr@email.yo


And when I click on country field I want to see ComboBox with list of countries from table countries.

How can I do it?


Best of all worlds. External Lists vs. Managed Metadata vs. Choice Columns


Hello All,

I have items I would like to store in Sharepoint lists and am having a hard time finding the best way to do this.

The criteria are:

1. Need a rapid way to enter information (such as is possible with datasheet view)

2. Need certain columns in the content type to be consistent.. Either from an External Lists (from our LOB system) or managed metadata.

Those two criteria seem to be at odds with each other. Using an external list would really be nice because I can keep certain field’s relational data intact, however I can't use datasheet view. Datasheet view is important because it allows copy and paste/tab through data entry when many rows must be entered.

Can a .sql file be bind into a datagrid or something else in WPF?


I am making a program, and want to add a .sql file to it.

And don't really know what I am doing to be honest.

Any help would be great



MS SQL Server: Search All Tables, Columns & Rows For Data or Keyword Query

If you need to search your entire database for specific data, this query will come in handy.

So when a client needs a custom report or some sort of custom development using Great Plains, most of the time I will have to track down the data in the system by running this query and find the table(s) it is in.

How to format and update GridView and DataGrid rows using JQuery

The behavior described in this question is as expected. When you set text of a cell in grid, it directly affects HTML that is going to be rendered. When you set text value of a cell, it means that you are setting innerText of the cell. The column that GridView creates for command fields (Edit, Delete and Select) are a (anchor) or button elements. So you can see what will happen if you set text value in that cell. It will wipe out those link or button controls and replace them with simple text string.

Use Jquery with repeater, gridview, datagrid

Before we talk about jquery inside any itemtemplate (repeater, gridview, datagrid), we need to understand the basic use of jquery functions

Adding Multiple Columns and Rows in GridView without using a Database

This article describes on how to add multiple columns and rows in GridView without using a database. Basically the GridView will be populated with data based on the values entered in each TextBoxes on Button Click and retain the GridView data on post back.
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend