2
I have a Datagrid in a form in C# WPF, as it is possible to execute a method recovers each Cell contained in that Datagrid and assign a possible value, or change the background color?
For example I have a Datagrid:
[ A ] [ D ] [ C ] [ C ]
[ B ] [ A ] [ B ] [ A ]
[ C ] [ A ] [ B ] [ D ]
And then I want to make a loop of repetition:
for (i<TamanhoDeLinhas) // Andar Linha
for(j<TamanhodeColunas) // Andar Coluna
if(DataGrid[i][j].Conteudo == A)
DataGrid[i][j].BackGround = Color.Red;
It is possible to do this?
Or else, I have the corresponding values of I J, or I know in which position the values will be! I have to change the Cell background on line i=2 and j=3. How is this possible? Recovers Cell and assigns a new color according to its position or by reading one by one?
The Datagrid in question is linked to a Datatable and it generates columns and rows automatically, in case it is dynamic. then I do Datagrid.Sourceitems = Datatable.Defaultview ... And so I play all the items for the Datagrid.
Any of the solutions is valid.
I have a Datatable, where it binds with Datagrid and it generates columns and rows automatically, in case it is dynamic. then I do Datagrid.Sourceitems = Datatable.Defaultview ... And so I play all the items for the Datagrid. When using this method you sent me appears the error message "The index was out of range. It should be non-negative and smaller than the collection size."
– Bruno Silva
In the case my table in question is 4 by 4 and as in the example you sent is 0|2 would have to have worked
– Bruno Silva
Add your question to the part of the code where you assign the grid dataContext or items, please. This message seems to occur pq Voce does not yet have the items in the grid.
– Aline
right, but for example, I link the items to Grid and created a button called updates, so after the data appears on the grid I call the button click event updates, and yet this error appears!
– Bruno Silva
Then, may I suggest that you do: Gd.Updatelayout(); after assigning the values. But in order to help, you’ll need to show the attribution code and the code that triggers the event to get the Cells.
– Aline
I put the update in another location and it worked, thanks so much for the help! solved my problem.
– Bruno Silva