2016-11-21 8 views
1

SQL Serverテーブルのデータを表示するTcxGridコンポーネントがあります。 CXGrid整数列に画像を表示するにはどうすればよいですか? この列のセルは、0または1にしかなりません。CXGrid整数列に画像を表示するにはどうすればよいですか?

整数の列セルの値が0の場合、 cximagelist.pictureインデックス= 0他 cximagelist.picture指数= 1

enter image description here

+1

ImageComboBoxカラムを試して、すべてのアイテムの説明を ''''に設定することができます。 –

答えて

0

あなたはImageComboBox列試みることができる:あなたはおそらく、フォームデザイナで視覚的に上記のほとんどを行うことができます

procedure Test(ACol: TcxGridColumn); 
var 
    props: TcxImageComboBoxProperties; 
    i: Integer; 
    item: TcxImageComboBoxItem; 
begin 
    ACol.PropertiesClass := TcxImageComboBoxProperties; 
    Assert(ACol.Properties is TcxImageComboBoxProperties); 
    props := TcxImageComboBoxProperties(ACol.Properties); 
    props.Images := YourImages; 
    for i in PossibleIndices do 
    begin 
    item := props.Items.Add; 
    item.Description := ''; // or IntToStr(i) 
    item.Value := i; 
    if i = 0 then 
     item.ImageIndex := 0 
    else 
     item.ImageIndex := 1; 
    end; 
end; 

を。

1
次のようにあなたは、非常に単純にこれを行うことができます

  1. を表示するには、グリッドに列を追加します。イメージを設定し、Propertiesの値をImageに設定します。

  2. 実行時に、2つのビットマップ、BM1BM2に表示するビットマップを指定します。

  3. 次のように、新しい列のOnCustomDrawCellにコードを追加します。

コード:もちろん

procedure TForm1.cxGrid1DBTableView1Column1CustomDrawCell(Sender: 
    TcxCustomGridTableView; ACanvas: TcxCanvas; AViewInfo: 
    TcxGridTableDataCellViewInfo; var ADone: Boolean); 
var 
    BM : TBitMap; 
    ARect : TRect; 
    I : Integer; 
begin 
    ARect := AViewInfo.Bounds; 

    // In the next line, 2 is the index of my integer column which 
    // contains the value which deterimnes the image to display. 

    I := AViewInfo.GridRecord.Values[2]; 
    if I = 0 then 
     BM := BM1 
    else 
     BM := BM2; 
    ACanvas.Draw(ARect.Left, ARect.Top, BM); 
    ADone := True; 
end; 

、あなたはグリッドに整数フィールドの値を表示したくない場合、あなたは、単にその列を削除したり、FalseにそのVisibleプロパティを設定することができます。

関連する問題