#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2013
    Posts
    42
    Rep Power
    2

    How to customize DBAdvGrid column ?


    I am trying to display data from database table into DBAdvGrid so that first column will show only checkbox, while other 3 columns will show label, description and image field from database table. I am using UniConnection, UniQuery, UniDatasource components to display data. I am setting UniConnection Database properties via code as I can give relative path of the database rather than full path. At object inspector it accepts only fiull path of database.

    My code is as follows At FormCreate event

    Code:
      
      filepath1 := ExtractFilePath(Application.ExeName);
      UniConnection1.Database := filepath1+'empdata.s3db';
      UniConnection1.Connected := True;
      UniQuery1.SQL.Text := 'Select '', label, description, image from emp';
      UniQuery1.Open;
    
      DBAdvGrid1.Columns[0].FieldName := '';
      DBAdvGrid1.Columns[2].FieldName := 'label';
      DBAdvGrid1.Columns[3].FieldName := 'description';
      DBAdvGrid1.Columns[4].FieldName := 'image';
    The above code connect and display data successfully but problem is with displaying data at DBAdvGrid as I want first column to display only checkbox (no data from DB). At DBAdvGrid I cannot set field name of particular column through object inspector as it is connecting to the database through code with by extracting path.

    I have set first column of DBAdvGrid editor type property to the edDataCheckBox so that it would display checkbox in first column but it is getting overlapped by label data, similarly at second column it is showing 'description' and at 3rd column image.

    How to customize it via code so that it would show

    1st column - No Data
    2nd column - label
    3rd column - description
    4th column - image

    What I am getting as

    1st column - label overlapped with checkbox
    2nd column - label
    3rd column - description
    4th column - image {MEMO}


    How to sort out this problem ?
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2008
    Posts
    356
    Rep Power
    7
    While I have the component, I've actually never used it, so not sure how it works...

    I do see that the columns have a property called Header. See if setting

    DBAdvGrid1.Columns[0].Header = '';
    works rather than the FieldName.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2013
    Posts
    42
    Rep Power
    2
    DBAdvGrid1.Columns[0].Header = '';

    also not working, I think I am setting these properties of DBAdvGrid into the FormCreate event of the form which not effecting.

    Do I have to write above code into any event of DBAdvGrid so that it would take effect ?
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2008
    Posts
    356
    Rep Power
    7
    Originally Posted by ninadgac
    DBAdvGrid1.Columns[0].Header = '';

    also not working, I think I am setting these properties of DBAdvGrid into the FormCreate event of the form which not effecting.

    Do I have to write above code into any event of DBAdvGrid so that it would take effect ?
    My guess would be anywhere after the query/table is opened. But again, I wasn't sure it would work, it just seemed that the header property of the column would override what the field name is, after all, you don't really want your users knowing the actual columns names in your database.

    You may have better luck asking the question on TMS's Forum.

    EDIT:
    Actually, did you try altering your field's property. Again, I don't have UniQuery, but the standard query Fields do have a DisplayLabel property,
    Query.fieldbyname('XXX').DisplayLabel := '';
    The regular DBGrid will use DisplayLabel for the column header if it has a value over the fieldname property of your field.
    Last edited by majlumbo; November 21st, 2013 at 10:27 AM.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2013
    Posts
    42
    Rep Power
    2
    Suppose if I used DBGrid inplace of DBAdvGrid then above type of customization possible at DBGrid ?
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2008
    Posts
    356
    Rep Power
    7
    You'd obviously have to add the code to display the check box in the column you want. Here's an article that show how to do so..

IMN logo majestic logo threadwatch logo seochat tools logo