Home - Forums-.NET - FlyGrid.Net (Windows Forms) - Bound and Image out of a Database

FlyGrid.Net (Windows Forms)

.NET Datagrid - Fast, highly customizable, industry standards .NET data grid control for WinForms

This forum related to following products: FlyGrid.Net

Bound and Image out of a Database
Link Posted: 14-Feb-2006 03:53
Hello,
I have a database with a BLOB/Picture field in and want to use databound grid to show the graphics.

I added the following code to the boundgridsample:

case TypeCode.Object:
        AutoHeightImageColumn imgcol = new AutoHeightImageColumn(dc.Caption, dc.ColumnName);
        imgcol.EditorStyle = EditorStyle.Simple;
        imgcol.ImageSizeMode = ImageSizeMode.StretchAndCenterImage;
        col = imgcol;
        break;

But I don't see the real images out of the table. Only a standpicture ( looks like a hill and a sun) is shown.

How I can show BLOB/PICTURES in the databound grid ?

Thanks and regards
Uwe
Link Posted: 14-Feb-2006 04:37
Can you send this database (not necessary full, some records is enough) to us () to solve this problem?
Link Posted: 14-Feb-2006 15:21
Thanks for the sample. This problem is solved, additional sample that shows how to prepare FlyGrid to display images in the data bound mode has been added to the FlyGrid.Net Demo.
Nearest FlyGrid.Net will available at the end of this week.
Link Posted: 17-Feb-2006 03:29
Hello,
i downloadwed the newest stuff but still have the same problem, that only a sample pic (hill with sun) is shown.

There is in my view only a small difference with the example. As I used the databound sample and do not know how many columns will be added it#s different to us the AddRange, so i used cols.Items.Add:

I added here the complete function. Is there something wrong ?


            bool bShow;
            bool bFiltering;
            grid.BeginInit();
            cols.Items.BeginInit();
            try
            {
                cols.Items.Clear();
                for (int i = 0; i < dataTable.Columns.Count; i++)
                {
                    DataColumn dc = dataTable.Columns[i];
                    Column col;

                    TypeCode tc = Type.GetTypeCode(dc.DataType);

                    // Festlegen der ?berschriften

                    switch (dc.ColumnName)
                    {
                        case "F_INDEX":
                            dc.Caption = "Index";
                            bShow = true;
                            bFiltering = false;
                            break;
                        case "F_BILD":
                            dc.Caption = "Bild/Symbol";
                            bShow = true;
                            bFiltering = false;
                            break;
                        case "F_KENNUNG":
                            dc.Caption = "Kennzeichen";
                            bShow = true;
                            bFiltering = true;
                            break;
                        default:
                            dc.Caption = "Text";
                            bShow = true;
                            bFiltering = false;
                            break;
                    }

                    switch (tc)
                    {
                        case TypeCode.Boolean:
                             col = new BooleanColumn(dc.Caption, dc.ColumnName);
                             break;
                        case TypeCode.String:
                        case TypeCode.Char:
                             col = new Column(dc.Caption, dc.ColumnName);
                             break;
                        case TypeCode.DateTime:
                             col = new DateTimeColumn(dc.Caption, dc.ColumnName);
                             col.EditorStyle = EditorStyle.DropDown;
                             break;
                        case TypeCode.Decimal:
                        case TypeCode.Single:
                        case TypeCode.Double:
                        case TypeCode.Int16:
                        case TypeCode.Int32:
                        case TypeCode.Int64:
                        case TypeCode.UInt16:
                        case TypeCode.UInt32:
                        case TypeCode.UInt64:
                        case TypeCode.Byte:
                             NumberColumn numcol = new NumberColumn(dc.Caption, dc.ColumnName);
                             numcol.NumberType = Type.GetTypeCode(dc.DataType);
                             numcol.TextAlign = ContentAlignment.MiddleRight;
                             if (tc == TypeCode.Decimal)
                                 numcol.FormatString = "C";//currency
                             else if (tc == TypeCode.Single)
                                 numcol.FormatString = "P";//percent
                             else
                                 numcol.EditorStyle = EditorStyle.Spin;

                             col = numcol;
                             break;
                        case TypeCode.Object:
                             ImageColumn imgCol = new ImageColumn(dc.Caption, dc.ColumnName);
                             imgCol.ShowImageInCell = true;
                             col = imgCol;
                             break;
                        default:
                             col = new Column(dc.Caption, dc.ColumnName);
                             break;
                    
                   }


                    col.ReadOnly = dc.ReadOnly | dc.AutoIncrement;

                    col.AllowFiltering = bFiltering;

                    if (cols.Items.Count == 0)
                        col.SortOrder = SortOrder.Ascending;
                    else if (cols.Items.Count == 1)
                        col.SortOrder = SortOrder.Descending;


                    if (col.Caption == "Index")
                    {
                        col.SortOrder = SortOrder.Ascending;
                        col.ReadOnly = true;
                    }

                                
                    col.Visible = bShow;

                    cols.Items.Add(col);

                }

            }
            finally
            {
                cols.Items.EndInit();
                grid.EndInit();
            }
Link Posted: 17-Feb-2006 03:34
Did you see Bound Features\Bound Images sample in the latest version?
This sample shows how to use ImageColumn and AutoHeightImageColumn classes to display images in databound mode.
Also -
Please check the version of FlyGrid that you're using - version should be 1.3.3
Link Posted: 17-Feb-2006 06:36
Yes - i use the 1.3.3.

i only change the AddRange method with cols.add method. but now graphic is shown.

is there a limitation of the graphic type ? in the table I have jpg and png graphics.
Link Posted: 17-Feb-2006 09:57
Yes, jpg and png images is supported. Perhaps problem in the DBVista formats, how images stored in database.
try follwing code to create image from some record:

private static Image GetImage(DataRowView dr, string fieldname)
{
  byte[] buff = dr[fieldName] as byte[];
  return buff != null ? Image.FromStream(new System.IO.MemoryStream(buff)) : null;
}


I would to know:
1. That returned by dr[fieldName]?
2. That returned by this method
Link Posted: 19-Feb-2006 21:15
I deleted the complete form and rewrite it from scratch based on the sample and now it works - I don't no why