Created
June 6, 2019 11:35
-
-
Save relliv/fa2cb5ec71b2b57393631d2f8e94e386 to your computer and use it in GitHub Desktop.
C# WFA Grid Cell If Contains Then Set Color
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Drawing; | |
using System.Windows.Forms; | |
namespace TestaWFA | |
{ | |
public partial class Form1 : Form | |
{ | |
public Form1() | |
{ | |
InitializeComponent(); | |
} | |
List<int> tablo1 = new List<int> { 444, 201 }; | |
List<int> tablo2 = new List<int> { 101, 423 }; | |
private void Form1_Load(object sender, EventArgs e) | |
{ | |
dataGridView1.DataSource = LoadCollectionData(); | |
for (int i = 0; i < dataGridView1.RowCount; i++) | |
{ | |
if (dataGridView1.Rows[i].Cells.Count > 0) | |
{ | |
if (!string.IsNullOrWhiteSpace(dataGridView1.Rows[i].Cells[0].Value.ToString()) && tablo1.Contains(Convert.ToInt32(dataGridView1.Rows[i].Cells[0].Value))) | |
{ | |
dataGridView1.Rows[i].Cells[1].Style.BackColor = Color.LawnGreen; | |
} | |
else if (!string.IsNullOrWhiteSpace(dataGridView1.Rows[i].Cells[0].Value.ToString()) && tablo2.Contains(Convert.ToInt32(dataGridView1.Rows[i].Cells[0].Value))) | |
{ | |
dataGridView1.Rows[i].Cells[1].Style.BackColor = Color.OrangeRed; | |
} | |
} | |
} | |
} | |
private List<Author> LoadCollectionData() | |
{ | |
List<Author> authors = new List<Author> | |
{ | |
new Author() | |
{ | |
ID = 101, | |
Name = "Mahesh Chand", | |
BookTitle = "Graphics Programming with GDI+", | |
DOB = new DateTime(1975, 2, 23), | |
IsMVP = false | |
}, | |
new Author() | |
{ | |
ID = 201, | |
Name = "Mike Gold", | |
BookTitle = "Programming C#", | |
DOB = new DateTime(1982, 4, 12), | |
IsMVP = true | |
}, | |
new Author() | |
{ | |
ID = 244, | |
Name = "Mathew Cochran", | |
BookTitle = "LINQ in Vista", | |
DOB = new DateTime(1985, 9, 11), | |
IsMVP = true | |
}, | |
new Author() | |
{ | |
ID = 423, | |
Name = "Mathew Cochran", | |
BookTitle = "LINQ in Vista", | |
DOB = new DateTime(1985, 9, 11), | |
IsMVP = true | |
}, | |
new Author() | |
{ | |
ID = 111, | |
Name = "Mathew Cochran", | |
BookTitle = "LINQ in Vista", | |
DOB = new DateTime(1985, 9, 11), | |
IsMVP = true | |
}, | |
new Author() | |
{ | |
ID = 344, | |
Name = "Mathew Cochran", | |
BookTitle = "LINQ in Vista", | |
DOB = new DateTime(1985, 9, 11), | |
IsMVP = true | |
}, | |
new Author() | |
{ | |
ID = 444, | |
Name = "Mathew Cochran", | |
BookTitle = "LINQ in Vista", | |
DOB = new DateTime(1985, 9, 11), | |
IsMVP = true | |
} | |
}; | |
return authors; | |
} | |
} | |
public class Author | |
{ | |
public int ID { get; set; } | |
public string Name { get; set; } | |
public DateTime DOB { get; set; } | |
public string BookTitle { get; set; } | |
public bool IsMVP { get; set; } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment