TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Albaraa Yaseen
NA
11
520
Changing the backcolor of a single cell in datatable
May 6 2020 3:35 PM
I'm making Bulls and Cows game in WPF And when the player tries to guess. The result will be displayed in DataTable which is banded to DataGrid and I want to do the next: if the number is bull then the backcolor of a cell which that number is put in will be red, and if the number is cow, it will be blue, so how to do that please?
void
filldatagrid()
{
table.Columns.Add(
"N1"
,
typeof
(
int
));
table.Columns.Add(
"N2"
,
typeof
(
int
));
table.Columns.Add(
"N3"
,
typeof
(
int
));
table.Columns.Add(
"N4"
,
typeof
(
int
));
table.Columns.Add(
"Cows"
,
typeof
(
int
));
table.Columns.Add(
"Bulls"
,
typeof
(
int
));
showing.ItemsSource = table.DefaultView;
}
private
void
Grid_Loaded(
object
sender, RoutedEventArgs e)
{
filldatagrid();
}
private
void
comparing()
{
int
a, b, c, d, cows = 0, bulls = 0;
a = (gussing / 1000) % 10;
b = (gussing / 100) % 10;
c = (gussing / 10) % 10;
d = gussing % 10;
if
(a == number[0] && b == number[1] && c == number[2] && d == number[3])
{
UserInput.Visibility = Visibility.Hidden;
_try.Visibility = Visibility.Hidden;
win.Visibility = Visibility.Visible;
thenumber.Visibility = Visibility.Visible;
thenumber.Content =
"The nubmber"
+ gussing.ToString();
}
else
{
if
(a == number[0])
{
bulls++;
/*what should be written here??*/
}
else
if
(a == number[1] || a == number[2] || a == number[3])
cows++;
if
(b == number[1])
bulls++;
else
if
(b == number[0] || b == number[2] || b == number[3]) cows++;
if
(c == number[2])
bulls++;
else
if
(c == number[0] || c == number[1] || c == number[3])
cows++;
if
(d == number[3])
bulls++;
else
if
(c == number[0] || c == number[1] || c == number[2])
cows++;
}
table.Rows.Add(a, b, c, d, cows, bulls);
}
Reply
Answers (
2
)
How to bind nested datagridview in WPF C#
How to hide the sort arrow in datagridcolmumn ?