Swap background color and item text in Gridview

Asked

Viewed 592 times

0

I have a GridView with multiple numbers and I have a click event on the items in this GridView. I would like the items that have already been clicked to change the background and text colors to show the user that they have already been clicked. If possible disable for future clicks.

The event is this:

private void dataGridNumbers_Tapped(object sender, TappedRoutedEventArgs e)
{
    string selectedNumber = dataGridNumbers.SelectedItem.ToString();

    if (selectedNumber == resposta)
    {
        txtBoxInfo.Text = "Congratulations! You Find the Ramdon Number!";
    }
    if (selectedNumber != resposta)
    {
        numbersCloser(Int32.Parse(selectedNumber));
    }
}
  • Sorry, I’m in Mexico and had asked the question on the stack in Spanish and did not answer me anything useful! My keyboard is Spanish and does not have all characters to write well in Portuguese.

  • I am creating to publish in the tent of Windows 10, is not Asp.net!

  • Spanish keyboards have all the accents that Portuguese uses.

1 answer

1


Use the event dataGridNumbers_CellClick

private void dataGridNumbers_CellClick(object sender, DataGridViewCellEventArgs e)
{
    dataGridView1.Rows[e.RowIndex].DefaultCellStyle.BackColor = Color.DarkGreen;
    dataGridView1.Rows[e.RowIndex].DefaultCellStyle.ForeColor = Color.Red;
    dataGridView1.Rows[e.RowIndex].ReadOnly = true;
}

UWP

GridView.Background = new SolidColorBrush(Windows.UI.Colors.Red);
  • Cassio, actually it is not dataGridView, in UWP only has Grid View! I tried using the example code, but Grid View has no Rows option. Thanks anyway.

  • I changed the code

  • Thank you, I’ll take a test here and let you know.

  • I put it this way: dataGridNumbers.Background = new Solidcolorbrush(Windows.UI.Colors.Red); but change me the color of all Gridview, not just the area occupied by the item that was clicked! I did not find the way to put Selecteditem or something similar to the Background exchange!

  • use the Getrow function to pick up the line, and then change the color

Browser other questions tagged

You are not signed in. Login or sign up in order to post.