From: Peter Duniho on
mick wrote:
> [...]
> > lbxTabProgList.Refresh(); //*** Tried
> this - doesnt work ***
> > lbxTabProgList.DataSource = null; // nulling then
> resetting the datasource does
> > lbxTabProgList.DataSource = progList; // work however
> > }
>
>> Dont think resetting the datasource is the right way so does anyone
>> know why the listbox
>> update to what it`s bound to?
>
>> Sorted it. Update() was the one I wanted.
>
> It worked the first time but doesnt work now, so back to the problem.
> Anyone?

The Refresh() and Update() methods in Control aren't related to data
binding. They simply deal with redrawing the visual on-screen after
some underlying data in the control changes. Normally you don't need
those methods at all, since changes typically cause a redraw to happen
automatically. And even when you might use them, they won't cause
underlying data to be updated; they simply cause the control to be redrawn.

I think what you want is the BindingList<T>.ResetItem() method. That
will alert other objects that are bound to the BindingList<T> object
that an individual item within the list has changed.

Note that the method takes as its argument an index, not a specific
object, while in your code you have a specific object but not an index.
Fortunately, this isn't really a problem because the code you've
posted actually isn't really the best way to deal with finding the right
object in the list and modifying it.

Try this instead:

private void btnChange_Click(object sender, EventArgs e)
{
int iitem = lbxTabProgList.SelectedIndex;
ProgItem item = progList[iitem];

item.Name = tbTabProgListName.Text;
item.Path = tbTabProgListLocation.Text;

progList.ResetItem(iitem);
}

Pete
From: mick on
"Peter Duniho" <no.peted.spam(a)no.nwlink.spam.com> wrote in message
news:%23Cdcaq3nKHA.1544(a)TK2MSFTNGP06.phx.gbl...
> mick wrote:
>> [...]
>> > lbxTabProgList.Refresh(); //*** Tried
>> this - doesnt work ***
>> > lbxTabProgList.DataSource = null; // nulling then
>> resetting the datasource does
>> > lbxTabProgList.DataSource = progList; // work however
>> > }
>>
>>> Dont think resetting the datasource is the right way so does anyone know
>>> why the listbox
>>> update to what it`s bound to?
>>
>>> Sorted it. Update() was the one I wanted.
>>
>> It worked the first time but doesnt work now, so back to the problem.
>> Anyone?
>
> The Refresh() and Update() methods in Control aren't related to data
> binding. They simply deal with redrawing the visual on-screen after some
> underlying data in the control changes. Normally you don't need those
> methods at all, since changes typically cause a redraw to happen
> automatically. And even when you might use them, they won't cause
> underlying data to be updated; they simply cause the control to be
> redrawn.
>
> I think what you want is the BindingList<T>.ResetItem() method. That will
> alert other objects that are bound to the BindingList<T> object that an
> individual item within the list has changed.
>
> Note that the method takes as its argument an index, not a specific
> object, while in your code you have a specific object but not an index.
> Fortunately, this isn't really a problem because the code you've posted
> actually isn't really the best way to deal with finding the right object
> in the list and modifying it.
>
> Try this instead:
>
> private void btnChange_Click(object sender, EventArgs e)
> {
> int iitem = lbxTabProgList.SelectedIndex;
> ProgItem item = progList[iitem];
>
> item.Name = tbTabProgListName.Text;
> item.Path = tbTabProgListLocation.Text;
>
> progList.ResetItem(iitem);
> }

Yep, thats the one. Thanks again.

mick