Note that there are some explanatory texts on larger screens.

plurals
  1. POGet datagridcell by value
    primarykey
    data
    text
    <p>I have a <code>datagrid</code>, which is bound to a <code>datatable</code>, each cell has a unique value, so no two cells have the same value. </p> <p>I want to change the cell with the value 1 (int32) to the color green. Note, the value of 1 is dynamic, thats just an example, it could be between 1-90.</p> <p>I have searched around, and most of the help gives you the value of either a cell based on its coordinates i.e. (4,2) or the selected cell. This isn't what I want, I want to change the color of a cell based on its value. </p> <p>Is there a way to do this, for example in JavaScript i would simply assign each cell an id equivalent to its value and then something like <code>$('#' + 1).css('background-color:green;')</code> (note: this might not be correct syntax, but you get the picture). Is there a way as simple as this or a standard way of doing this?</p> <p>My datagrid</p> <pre><code>&lt;DataGrid Name="grid" ItemsSource="{Binding}" Height="300" Width="900" AutoGenerateColumns="True" VerticalScrollBarVisibility="Disabled" HorizontalAlignment="Center" VerticalAlignment="Top" RowHeight="40"&gt; &lt;DataGrid.ItemsPanel&gt; &lt;ItemsPanelTemplate&gt; &lt;WrapPanel Orientation="Vertical" /&gt; &lt;/ItemsPanelTemplate&gt; &lt;/DataGrid.ItemsPanel&gt; &lt;/DataGrid&gt; </code></pre> <p>Table creation</p> <pre><code>DataSet dataSet = new DataSet("myDS"); DataTable numbersTable = new DataTable("Numbers"); numbersTable.Columns.Add("Number", typeof(Int32)); for (int i = 1; i &lt; 91; i++) { numbersTable.Rows.Add(i); } dataSet.Tables.Add(numbersTable); grid.DataContext = numbersTable.DefaultView; </code></pre>
    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.
 

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