1. Welcome Guest! In order to create a new topic or reply to an existing one, you must register first. It is easy and free. Click here to sign up now!.
    Dismiss Notice

.NET Question: Problem with databinding in own custom generic objects.

Discussion in 'Microsoft News' started by NewsBot, Mar 27, 2008.

  1. NewsBot

    NewsBot I Got News

    Joined:
    Feb 8, 2006
    Messages:
    1,813
    Operating System:
    Windows Vista Home Premium
    Hi All,

    I've run into a problem and I thought I'd throw it open to some people more clever than I!

    Basically I have created my own 'ConfigKeys' object that under the hood uses a Generic List(of ConfigKey) to do the datastore.
    I have a vb.net UI, with a datagridview that uses my object as a datasource.

    My problem is that if I add a new ConfigKey to the ConfigKeys list using my object model, the datagridview doesn't show the newly added item, even if I call datagridview.refresh.

    Here's some pseudo VB.net code:

    <!--fonto:Courier New--> Courier New <!--/fonto--><b>private function doAdd()
    ***oUser.ConfigKeys.add(new ConfigKey("name","value")
    ***datagridView1.refresh()
    end function</b><!--fontc--><!--/fontc-->

    The wierd thing is that if I put a breakpoint on the line after the refresh() and query the oUserConfig keys count, it's correct, but the datagridgridview.rows count is 1 less.
    The only way I've gotten the grid to update is to disconnect the datasource and reconnect it...

    <!--fonto:Courier New--> Courier New <!--/fonto--><b>private function doAdd()
    ***oUser.ConfigKeys.add(new ConfigKey("test","key", "etc")
    ***datagridView1.datasource = nothing
    ***datagridView1.datasource = oUser.ConfigKeys()
    end function

    </b><!--fontc--><!--/fontc-->
    The grid is still definately connected to the datasource - if I change one of the config keys through the configKeys model, then the grid will show the changes.
    I'm guessing there's something I need to do in my object model to tell any databound items that the size of the items has changed??

    Any ideas? It's been a while since I've worked on something like this.

    Thanks in anticipation.
    Richard.






     

Share This Page