1

以下のように、最後の列にいくつかの異なる色のラベルを持つグリッドが必要です。1 つのラベルを使用する方法はわかっていますが、4 つ必要で、グリッド上の値 (değer) で表示または非表示にする必要があります。

例えば

  if value is below 20 the red label will appear,

  if value is over 40 the yellow and orange will appear same time,

  if value is between 20-40 green label will appear... 

どんな助けでも大歓迎です。

グリッド

4

2 に答える 2

2

次のような関数が必要です。

void UpdateGridColumnLabels(int index){
    int width = column.Width;
    int height = gridRow.Height;
    Bitmap bmp = new Bitmap(width, height, g);
    Graphics g = Graphics.FromImage(bmp);
    if(value < 20)
        g.FillRect(Brushes.Red, 0, 0, width / 3, height);
    else if(value >= 20 && value < 40)
        g.FillRect(Brushes.Orange, width/3, 0, width / 3, height);
    else
        g.FillRect(Brushes.Yellow, 2 * width/3, 0, width / 3, height);
    gridViewImageColumn[index] = bmp;
}

ここでは、セルに収まるビットマップを作成しています。次に、Graphics クラスを使用して、条件に応じてラベルを動的に追加します。その後、このラベル付きビットマップがセルのコンテンツになります。

于 2016-05-31T09:25:03.087 に答える