Sortere datagrid baseret på cell farve.
Hej alle sammen.Jeg har en datagrid med 2 celler
en med billede i, og en der hedder [Users].
Jeg skal sortere min datagrid, baseret på farven (forecolor) som teksten har da det er en del af en chat.
Admins skal først, de har farven Color.PaleGoldenrod
så moderators, de har farven Color.LightSkyBlue
og til sidst normale brugere som har farven Color.White
jeg prøvede
-----------------------------------------------
public void SortUsers()
{
DataGridViewRow[] grid = new DataGridViewRow[dataGridView2.Rows.Count];
int currentindex = 0;
foreach (DataGridViewRow row in dataGridView2.Rows)
{
if (row.Cells["Users"].Style.ForeColor == Color.PaleGoldenrod)
{
grid[currentindex] = row;
currentindex++;
}
}
foreach (DataGridViewRow row in dataGridView2.Rows)
{
if (row.Cells["Users"].Style.ForeColor == Color.LightSkyBlue)
{
grid[currentindex] = row;
currentindex++;
}
}
foreach (DataGridViewRow row in dataGridView2.Rows)
{
if (row.Cells["Users"].Style.ForeColor == Color.White)
{
grid[currentindex] = row;
currentindex++;
}
}
dataGridView2.Rows.Clear();
dataGridView2.Rows.AddRange(grid);
dataGridView2.Refresh();
}
-----------------------------------------------
men den crashede hele tiden
så nogen der har nogle ideér til at gøre dette effectiv ?
takker.