Style Data in a gridview which dynamically generates the columns

Posted by Coesy on Stack Overflow See other posts from Stack Overflow or by Coesy
Published on 2010-05-18T11:08:15Z Indexed on 2010/05/18 11:10 UTC
Read the original article Hit count: 219

Filed under:
|
|

I have built a dynamic gridview using the following code

 grdVariants.Columns.Clear();
 int i = 0;
 foreach (DataColumn column in options.Columns)
 {
     grdVariants.Columns.Add(new GridViewColumn
     {
         Header = column.ColumnName,
         DisplayMemberBinding = new Binding(string.Format("[{0}]", i++))
     });
 }

This will dynamically generate my columns at runtime, I then bind the data using

lstVariantsGrid.DataContext = options;
lstVariantsGrid.Items.Refresh();

This all works great and shows the data in the correct columns etc, the only issue i have is that I can't style the rows like I would in xaml as it is all an unknown quantity until runtime. Can anyone offer some advice on how I might go about doing this?

One of the biggest problems I have is that one of the columns needs to display the image rather than just the path which it currently shows, as well as fiddling with fonts and colors etc.

Thanks for your time.

© Stack Overflow or respective owner

Related posts about wpf

Related posts about gridview