TcxDBImage.DataBinding Property
Provides access to data binding settings.
Declaration
property DataBinding: TcxDBEditDataBinding read; write;
Property Value
Type | Description |
---|---|
TcxDBEditDataBinding | Stores data binding editor settings. |
Remarks
You can use DataBinding
.DataSource and DataBinding
.DataField properties to bind the data-aware image editor to data.
Refer to the TcxDBEditDataBinding class description for detailed information on all available options.
Important
Ensure that the bound dataset field contains image data; otherwise, an error may occur.
Blob Fields and Supported Image Formats
We recommend that you set the Properties.GraphicClass property to TdxSmartImage to ensure that the TcxDBImage editor supports the following image formats:
- BMP | EMF | GIF | JPEG | PNG | TIFF | WMF
- Support for these image formats relies on corresponding native encoders from the Windows Imaging Component (WIC).
- SVG
- DevExpress controls use our own SVG engine implementation. Refer to the following topic for detailed information on supported SVG elements and their attributes: SVG Image Support.
Code Examples
Bind to Data
The following code example creates a BLOB field in a TdxMemData component and binds a TcxDBImage editor to the field:
uses
dxGDIPlusClasses; // This unit declares the TdxSmartImage class
// ...
var
AFieldDef: TFieldDef;
begin
if dxMemData1.Active then
dxMemData1.Close;
AFieldDef := dxMemData1.FieldDefs.AddFieldDef;
AFieldDef.Name := 'MyImageField';
AFieldDef.DataType := ftBlob;
AFieldDef.CreateField(dxMemData1);
DataSource1.DataSet := dxMemData1;
DataSource1.Enabled := True;
cxDBImage1.DataBinding.DataSource := DataSource1;
cxDBImage1.DataBinding.DataField := 'MyImageField';
cxDBImage1.Properties.GraphicClass := TdxSmartImage; // Selects the universal container
dxMemData1.Open;
end;
Load an Image from a File
The following code example allows users to select and load an image file to the bound BLOB dataset field in a TdxMemData component:
var
ADataBinding: TcxDBEditDataBinding;
AField: TBlobField;
begin
ADataBinding := cxDBImage1.DataBinding;
dxOpenPictureDialog1.Execute(Handle);
if ((dxOpenPictureDialog1.FileName = '') or (not ADataBinding.CanModify)) then Exit;
dxMemData1.DisableControls;
try
dxMemData1.Append;
AField := ADataBinding.Field as TBlobField;
AField.LoadFromFile(dxOpenPictureDialog1.FileName);
dxMemData1.Post;
finally
dxMemData1.EnableControls;
end;
end;