Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There are two ways to do it, In both scenario, you need to set <strong>AutoGenerateColumn to false</strong>.</p> <ol> <li>If you already know the columns you want to display in the grid during design time, add the columns in the XAML directly.</li> <li>If you do not know the column during design time and if it comes from database with some attribute describing the order and visibility then add autogeneratingcolumn event and in the event, you can make the column visible or do not create the column and even change the order.</li> </ol> <p>*<strong><em>EDIT</em>*</strong> <br></p> <blockquote> <p>grid.ItemsSource = Product.GetProducts(200);<br> grid.AutoGeneratingColumn += grid_AutoGeneratingColumn;</p> </blockquote> <p><br></p> <blockquote> <p>void grid_AutoGeneratingColumn(object sender, DataGridAutoGeneratingColumnEventArgs e) { string headername = e.Column.Header.ToString();</p> </blockquote> <pre><code> switch (headername) { case "Line": case "Color": e.Cancel = true; //Cancel the columns don't want to generate break; case "Name": e.Column.Header = "Name Modified"; e.Column.DisplayIndex = 1; break; case "Price": e.Column.Header = "Price header"; e.Column.DisplayIndex = 0; break; default: e.Cancel = true; break; } } </code></pre> <p><br></p> <p>As you can see from the example, Price comes after Name, but not only changed the header I also changed the display order. If you would run, price comes as the first column and Name comes as second column and all other columns are removed from displaying. <br> <a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.datagrid.autogeneratingcolumn(v=vs.95).aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/system.windows.controls.datagrid.autogeneratingcolumn(v=vs.95).aspx</a></p> <p>Hope this helps.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload