locked
Update Datagridrow on each click RRS feed

  • Question

  • I have a table that contains articles, I put a column in my table to find if my article is Starred, I used a column that contains 0 (not starred) and 1 (starred). 

    I display a star next to the items starred in a datagrid. 
    Top of the datagrid I have a button (with a star) which allows the artcicles starred. 

    he must play two roles. 
    When you click it should automatically bring up a star next to the selected item and click again when you have the star must disappear and each time the code has to go to the database ans update  by day 0 or 1. 

    At the moment here is what I  did,  I use DataTriggers to display stars when the value of the column is 0 or 1 
     <DataGrid.RowStyle>
                            <Style TargetType="DataGridRow">
                                <Setter Property="Background" Value="White" />
                                <Style.Triggers>
                                      
    								<DataTrigger Binding="{Binding Path=starred}" Value="1">
                                        <Setter TargetName="img" Property="Source"  Value="star_yellow.png"></Setter>
                                    </DataTrigger>
                                </Style.Triggers>
                            </Style>
    </DataGrid.RowStyle>


    Onclick i update the table and I still click again nothing happens 

    This is what I want to do. 
    When you click on the button starred a star must appear next to the artcile and when you click again yet, the star should disappear. and each time the table in database must be updated. 

    I think use this same code on another button Mark all as Read / Unread, when you click this button, all database entries should be marked as read, and click again, all entries must be marked as unread. 

    The action must be instantaly without click on another buton to reload datagrid .. 

    Is that possible? 
    Thank you kindly help me 
    Monday, March 10, 2014 11:16 AM

Answers

  • http://msdn.microsoft.com/en-us/library/system.componentmodel.inotifypropertychanged(v=vs.110).aspx

    Basically you implement this interface so that the UI knows when you have made changes to the data being displayed in code.  Without it the GUI stays the same as you have seen.


    Lloyd Sheen

    • Proposed as answer by Leo (Apple) Yang Wednesday, March 12, 2014 6:03 AM
    • Marked as answer by CPGTech Hub Friday, March 14, 2014 2:28 PM
    Tuesday, March 11, 2014 6:12 PM

All replies

  • Are the classes you are binding to implementing the INotifyPropertyChanged interface?  You must implement this if your code changes the data so that the GUI will know about the changes.

    Lloyd Sheen

    Monday, March 10, 2014 4:48 PM

  • No,i did not implemented   INotifyPropertyChanged.

    please , Can you give me a link that better explains the implementation of INotifyPropertyChanged. 
    thank you for your reply
    Tuesday, March 11, 2014 4:52 PM
  • http://msdn.microsoft.com/en-us/library/system.componentmodel.inotifypropertychanged(v=vs.110).aspx

    Basically you implement this interface so that the UI knows when you have made changes to the data being displayed in code.  Without it the GUI stays the same as you have seen.


    Lloyd Sheen

    • Proposed as answer by Leo (Apple) Yang Wednesday, March 12, 2014 6:03 AM
    • Marked as answer by CPGTech Hub Friday, March 14, 2014 2:28 PM
    Tuesday, March 11, 2014 6:12 PM