in

C1 Community

ComponentOne Community is a free source for developers and help authors to collaborate and communicate.

TDBDropDown with TDBGrid has problem

Last post 03-31-2008 12:11 PM by vbogey. 3 replies.
Page 1 of 1 (4 items)
Sort Posts: Previous Next
  • 03-30-2008 9:20 AM

    TDBDropDown with TDBGrid has problem

    Scenario 

    I have a DB table of categories named "Categories" and a table of products named "Products", they both are linked with "CatID" as foreign key in Products table.

    In grid I want to show the combo from "Categories" table to select from all categories and on saving I want to update the "CatID" of selected category in "Products" table.

    Implementation 

    In TDBGrid I set Category column datafield to "CategoryName". Filled the combo with "Categories" table by binding it to filled Dataset, set its "DisplayMember" to "CategoryName" and "ValueMember" to "CatID".

    In TDBGrid, set the "Category" column's "DropDown" property to the name of drop down.

    The category ID field names are same in the Datasets for both DropDown and Grid.

     Problem

    When I run the application it raises error "DataField or Caption not found".

    I also tried setting the TDBGrid column's datafield to "CatID" to match with Combo's "ValueMember" but still the same error and its showing CatIDs in grid column instead of names.

    I there any thing missing to link DropDown to Grid?

    Please explain in detail how it will works. 

     

  • 03-30-2008 10:10 AM In reply to

    Re: TDBDropDown with TDBGrid has problem

     

    "DataField or Caption not found" tells you that your code is using a reference to a non existing column in the grid or dropdown.

    Usually this happens when you make changes to DataTable bound to the control (i.e. rename column) or typo in your code when referencing grid column (i.e. grid["NonExistingColumnName"]).

    If you use Unbound columns check them first!

    If your code is OK you will need to reset references to all columns for both controls using the latest DataTable definitions from the DataSet. Please note that you will need to redo your grid/dropdown formatting.

    To do this I suggest

    1, Clear DataSource (set as None)

    2. Set  DataSource to your DataTable (Products/Categories)

    After that verify:

    • ValueMember/DisplayMember of Dropdown
    • ValueTranslate of Dropdown
    • Dropdown property of the grid

    Bogdan

  • 03-30-2008 11:01 AM In reply to

    Re: TDBDropDown with TDBGrid has problem

    Bogdan,

    Thanks for your reply.

    I have added all grid and combo columns at design time and then binded both at run time using control.SetDataBinding(...  because I don't want to show extra columns (i.e. database id fields etc.)

    If I bind combo using DataSource property, it is working without any error but it reformat combo and showing all fields with field names in header.

     What should I have to set the Grid's "Category" column to "CategoryName" OR "CatID" ? because on clicking save button on form I have to update Products table with new selected "CatID" values. Can I get the CatID of newly selected category if I set Category column to "CategoryName"?

    Can you please explain me in brief what should be the grid's Category column DataField set to, what shuold be the combo's ValueMember and DisplayMember so I can get the new CatID of each row at run time.

     I am very thankful to you in advance.

     

     

  • 03-31-2008 12:11 PM In reply to

    Re: TDBDropDown with TDBGrid has problem

    It feels to me that you need a little into to C1TrueDBGrid/C1TrueDBDropdown.

    Reviewing existing C1TDBGrid examples (i.e. Tutorial08) would be my first suggestion.

    To answer your particular question

    1.       Try to erase everything you have done so far using SetDataBinding(). This is not needed for what you are trying to accomplish.

    2.       Create BindingSources (i.e. drop your both tables from your DataSource into your grid and dropdown respectively). I understand you have tested that part.

    3.       Configure Dropdown control:

    a.       Verify DataSource (should say something like: categoriesBindingSource)

    b.      Set  DisplayMember to “CategoryName”

    c.       Set  ValueMember to “CatID”

    d.      Set ValueTranslate=True

    4.       Configure DBGrid control:

    a.       Set Dropdown property to an instance of your dropdown

    At this stage you are only building and testing  your logic and ignoring presentation.

    5.       Build and run it. If this works as expected go to the next step (Presentation)

    6.       Use Design from the context menu to edit Grid presentation:

    a.       Use Caption property on Column Tab to control displayed column heading

    b.                  Use Visible on “Display Column” Tab to Show/Hide column (or use Splits/DisplayColumns  from Properties)

    7.       Configure Dropdown presentation:

    a.       Use Columns Property to change Caption

    b.      Use DisplayColumns to set visibility of any dropdown column.

                                                                   i.      Note (bizarre but true) :

    YOU MUST SET WITH=0 AND VISIBLE=False TO MAKE COLUMN HIDDEN

    I have just realized that that last note I wrote was most likely the source of your headache.

    Good luck,Bogdan  

     

Page 1 of 1 (4 items)
Contact ComponentOne: 1.800.858.2739 ©1987-2008 ComponentOne LLC All Rights Reserved.