Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
560
Clear datasource problem
posted

Hello again,

I want to clear the datasource bound to a combo. When I am using .SetDataBinding(Nothing, Nothing, True) the rows are removed like supposed. After setting the old valid datasource again the combo shows all columns of my datasource even if it should only show a few. What is the supposed way to clear the datasource?

Thanks,
Stefan

  • 469350
    Suggested Answer
    Offline posted

    Hi Stefan,

    When you bind the combo to a new data source, it builds the layout based on that data source.

    If you are setting up the layout at design-time, by hiding or sizing columns, then that layout will be lost as soon as you set the DataSource to Nothing.

    There are two ways you can deal with this:

    1) Set up the layout inside the InitializeLayout event. This event will fire whenever the DataSource of the combo changes, so you can write the code once and it will get hit every time you change the data source.

    2) Before setting the data source to nothing, save the layout using combo.DisplayLayout.Save. Then when you set the datasource back to the real one, you can load the saved layout using the Load method.