2
I have a method where I can change the color of a line in my Datagrid.
I followed through this link: Link
The problem is being like taking out the selection from when it is painted. Type, go back to the original color.
I tried it the following way:
public void alterarCorLinhaSelecionada()
    {
        int selectedIndex = dataGridAtribuicaoVaga.SelectedIndex;
        //Guarda a Row selecionada
        DataGridRow row =
                  dataGridAtribuicaoVaga.ItemContainerGenerator.ContainerFromIndex(selectedIndex) as DataGridRow;
        if (row == null)//A linha selecionada não está visivel
        {
            object item2 = dataGridAtribuicaoVaga.Items[selectedIndex];
            dataGridAtribuicaoVaga.ScrollIntoView(item2);//Torna a linha selecionada visivel
            row = dataGridAtribuicaoVaga.ItemContainerGenerator.ContainerFromIndex(selectedIndex) as DataGridRow;
        }
        var bc = new BrushConverter();
        if (row.IsSelected)
            row.IsSelected = false;
        else
            row.Background = (Brush)bc.ConvertFrom("#169FDB");
    }
In this case the error occurs in the row where it picks up column 2
Object item = dataGridAtribuicaoVaga.SelectedItem;
        if (dataGridAtribuicaoVaga.SelectedCells.Count > 0)
        {
            cod = Convert.ToInt32((dataGridAtribuicaoVaga.SelectedCells[1].Column.GetCellContent(item) as TextBlock).Text);
            desc = (dataGridAtribuicaoVaga.SelectedCells[2].Column.GetCellContent(item) as TextBlock).Text;
            min = Convert.ToInt32((dataGridAtribuicaoVaga.SelectedCells[3].Column.GetCellContent(item) as TextBlock).Text);
            med = Convert.ToInt32((dataGridAtribuicaoVaga.SelectedCells[4].Column.GetCellContent(item) as TextBlock).Text);
            max = Convert.ToInt32((dataGridAtribuicaoVaga.SelectedCells[5].Column.GetCellContent(item) as TextBlock).Text);
        }
        p1 = new Modelos.PerfilVagaAtribuicoes();
        atribuicao = new Atribuicao();
        p1.Codigo = cod;
        p1.Descricao = desc;
        p1.PontuacaoMin = min;
        p1.PontuacaoMed = med;
        p1.PontuacaoMax = max;
        if (!_editList.Any(items => items.Codigo == p1.Codigo))
            _editList.Add(p1);
Error:
An Exception of type 'System.Argumentoutofrangeexception' occurred in Presentationframework.dll but was not handled in user code Additional information: Specified argument was out of the range of Valid values.
Probably the dataGridAtribuicaVaga.Selectedcells must be with Length = 0
– PauloHDSousa
What do you mean Paul? but there is some solution?
– Emerson