How do I force the spread to update from the Datasource.

Posted by: joe-customer on 8 September 2017, 2:53 pm EST

  • Posted 8 September 2017, 2:53 pm EST

    I'm using a simple List(Of SomeType) as my DataSource.

    The problem is, when I update an instance of asrLabelValues directly through code, it doesn't automatically update in the spread until I move to another row in the spread.

    I therefore need to be able to tell the spread to requery the bound data after I update one of the bound items directly through code instead of through the spread cells.

    What do I call to force the spread to re-query it's datasource and update itself?

    <font size="3" face="Times New Roman">

    </font><b><span style="font-family:Consolas;font-size:10pt;">     </span></b><span style="color:green;font-family:Consolas;font-size:10pt;">Private</span><b><span style="font-family:Consolas;font-size:10pt;"> </span></b><span style="color:green;font-family:Consolas;font-size:10pt;">Sub</span><b><span style="font-family:Consolas;font-size:10pt;"> BuildDatasource()</span></b><span style="font-family:Consolas;font-size:10pt;"><o:p></o:p></span>

    <blockquote><blockquote>

    <font size="3" face="Times New Roman">

    </font><b><span style="font-family:Consolas;font-size:10pt;">
    _myDataSource = </span></b><span style="color:green;font-family:Consolas;font-size:10pt;">New</span><b><span style="font-family:Consolas;font-size:10pt;">
    List(</span></b><span style="color:green;font-family:Consolas;font-size:10pt;">Of</span><b><span style="font-family:Consolas;font-size:10pt;"> asrLabelValues)</span></b><span style="font-family:Consolas;font-size:10pt;"><o:p></o:p></span>

    <font size="3" face="Times New Roman">

    </font><b><span style="font-family:Consolas;font-size:10pt;">
    _myDataSource.Add(</span></b><span style="color:green;font-family:Consolas;font-size:10pt;">New</span><b><span style="font-family:Consolas;font-size:10pt;">
    asrLabelValues </span></b><span style="color:green;font-family:Consolas;font-size:10pt;">With</span><b><span style="font-family:Consolas;font-size:10pt;">
    {.LabelSetName = </span></b><span style="font-family:Consolas;font-size:10pt;">"Zero"</span><b><span style="font-family:Consolas;font-size:10pt;">, ...})</span></b><span style="font-family:Consolas;font-size:10pt;"><o:p></o:p></span>

    <font size="3" face="Times New Roman">

    </font><b><span style="font-family:Consolas;font-size:10pt;">
    _myDataSource.Add(</span></b><span style="color:green;font-family:Consolas;font-size:10pt;">New</span><b><span style="font-family:Consolas;font-size:10pt;">
    asrLabelValues </span></b><span style="color:green;font-family:Consolas;font-size:10pt;">With</span><b><span style="font-family:Consolas;font-size:10pt;">
    {.LabelSetName = </span></b><span style="font-family:Consolas;font-size:10pt;">"One"</span><b><span style="font-family:Consolas;font-size:10pt;">, ...})</span></b><span style="font-family:Consolas;font-size:10pt;"><o:p></o:p></span>

    <font size="3" face="Times New Roman">

    </font><b><span style="font-family:Consolas;font-size:10pt;">
    _myDataSource.Add(</span></b><span style="color:green;font-family:Consolas;font-size:10pt;">New</span><b><span style="font-family:Consolas;font-size:10pt;">
    asrLabelValues </span></b><span style="color:green;font-family:Consolas;font-size:10pt;">With</span><b><span style="font-family:Consolas;font-size:10pt;">
    {.LabelSetName = </span></b><span style="font-family:Consolas;font-size:10pt;">"Two"</span><b><span style="font-family:Consolas;font-size:10pt;">, ...})</span></b><span style="font-family:Consolas;font-size:10pt;"><o:p></o:p></span>

    <font size="3" face="Times New Roman">

    </font><b><span style="font-family:Consolas;font-size:10pt;">
    _myDataSource.Add(</span></b><span style="color:green;font-family:Consolas;font-size:10pt;">New</span><b><span style="font-family:Consolas;font-size:10pt;">
    asrLabelValues </span></b><span style="color:green;font-family:Consolas;font-size:10pt;">With</span><b><span style="font-family:Consolas;font-size:10pt;">
    {.LabelSetName = </span></b><span style="font-family:Consolas;font-size:10pt;">"Three"</span><b><span style="font-family:Consolas;font-size:10pt;">, ...})</span></b><span style="font-family:Consolas;font-size:10pt;"><o:p></o:p></span>

    <font size="3" face="Times New Roman">

    <span style="font-family:Consolas;font-size:10pt;">_activeSheet.DataSource = _myDataSource<o:p></o:p></span></font>

    </blockquote></blockquote>

    <b><span style="font-family:Consolas;font-size:10pt;">    
    </span></b><span style="color:green;font-family:Consolas;font-size:10pt;">End</span><b><span style="font-family:Consolas;font-size:10pt;"> </span></b><span style="color:green;font-family:Consolas;font-size:10pt;">Sub<o:p></o:p></span>

    <font size="3" face="Times New Roman">

    </font><font size="3" face="Times New Roman">

    </font>

  • Replied 8 September 2017, 2:53 pm EST

    It seems the simplest solution is to just use .NET's BindingSource rather than List(Of ...)

    That also allows for calling ...

    BindingSource.ResetCurrentItem()

    or

    BindingSource.ResetBindings(False)

    Though I didn't find I needed to do that.

  • Replied 8 September 2017, 2:53 pm EST

    Hi,

    I think if you use BindingList instead, it will update automatically.  BindingList supports ListChanged notifications, but List does not.

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels