Clicketyboo

Defined a list view and one column contains a label and a column like so:

                    <GridViewColumn Header="Document Class" Width="300">
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <StackPanel Orientation="Horizontal">
                                    <Label Content="{Binding ClassDescription}" HorizontalAlignment="Left" VerticalAlignment="Top" Height="25" Width="100">
                                    </Label>
                                    <Button x:Name="btnSelectClass" Content="..." HorizontalAlignment="Right" VerticalAlignment="Top" Click="Button_Click"></Button>
                                </StackPanel>
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>


Well, partially this is working for me. When the button in that item is clicked, the Button_Click event is fired and I can access the actual row quite easily:
    Private Sub Button_Click(oSender As Object, e As RoutedEventArgs)
        Dim oAttachmentEntry As AttachmentEntry

        oAttachmentEntry = oSender.DataContext

        oAttachmentEntry.ClassDescription = "meh"

    End Sub

What I don't understand is how to get this new "meh" value reflected back on the actual list view that's displayed to the user. After this code is executed the listview still displays the original value.

I reckon I need to somehow invoke "updateSource"? but at this state I'm hopelessly lost. I'm a WPF newbie...

Cheers


P
LVL 4
WernerVonBraunAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

WernerVonBraunAuthor Commented:
Never mind.... I figured it out:

    Private Sub Button_Click(oSender As Object, e As RoutedEventArgs)
        Dim oAttachmentEntry As AttachmentEntry
        Dim oMeh As BindingExpression

        oAttachmentEntry = oSender.DataContext

        oAttachmentEntry.ClassDescription = "meh"

        oMeh = oSender.Parent.Children.item(0).GetBindingExpression(Label.ContentProperty)
        oMeh.UpdateTarget()

    End Sub


Having said that though, I dare say this is a clumsy way of doing it. If anybody can suggest a better and easier way, I'm all ears. If not, I'm accepting this, my own answer soon, but if somewhere out there can tell me how to do this better, ALL THE POINKS ARE BELONG TO YOU.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
MikeTooleCommented:
In general, I'd say that the better method is via the use of the MVVM pattern.
Essentially, the data context of the View (Window) is a View Model class which should implement an OnPropertyChanged() method. That handles the notification of the change to the WPF framework.
I would then use the code-behind button click to assign the ClassDescription Property in the View Model
0
WernerVonBraunAuthor Commented:
If you could translate that into code that is easy to understand for a total newbie like me, the poinks are yours.
0
WernerVonBraunAuthor Commented:
ah well
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Development

From novice to tech pro — start learning today.