I decided myself, I just had to update the collection to which the output from the database was attached.
Solution: The class in which all this happens implements the interface INotifyPropertyChanged Element in XAML markup:
<ListView x:Name="contains" ItemsSource="{Binding ItemsForContains}" SelectedItem="{Binding SelectedItemsContains}"> <ListView.View> <GridView> <GridViewColumn DisplayMemberBinding="{Binding UserLogin}"/> <GridViewColumn> <GridViewColumn.CellTemplate> <DataTemplate> <StackPanel> <Image x:Name="clear" Style="{StaticResource image}" MouseLeftButtonUp="clearProf_MouseLeftButtonUp" ToolTip="ΠΡΠΈΡΡΠΈΡΡ" Source="images/clear.png"></Image> // ΠΠ½ΠΎΠΏΠΊΠ° </StackPanel> </DataTemplate> </GridViewColumn.CellTemplate> </GridViewColumn> </GridView> </ListView.View> </ListView>
Properties:
public ObservableCollection<Contains> ItemsForContains { get; set; } private Contains _SelectedItemsContains; public Contains SelectedItemsContains { get { return _SelectedItemsContains; } set { _SelectedItemsContains = value; RaisePropertyChanged(); } }
Implementing INotifyPropertyChanged:
protected void RaisePropertyChanged([CallerMemberName] string propertyName = null) => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); public event PropertyChangedEventHandler PropertyChanged;
The output from the database was as follows:
ItemsForContains = new ObservableCollection<Contains>(); connection.Open(); MySqlCommand contains = new MySqlCommand("SELECT * FROM groups WHERE groupId='" + id + "' LIMIT " + num, connection); // Π²ΡΠ±ΠΎΡΠΊΠ° ΠΈΠ· ΠΠ MySQL MySqlDataReader contains_result = contains.ExecuteReader(); if (contains_result.HasRows) { while (contains_result.Read()) // Π·Π°ΠΏΠΎΠ»Π½ΡΠ΅ΠΌ ΠΊΠΎΠ»Π»Π΅ΠΊΡΠΈΡ Π² ΡΠΈΠΊΠ»Π΅ { ItemsForContains.Add( new Contains() { CId = contains_result["id"].ToString(), UserId = contains_result["userId"].ToString(), UserLogin = contains_result["userLogin"].ToString() }); } connection.Close(); }
Action with base:
private void clear_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) // ΠΎΠ±ΡΠ°Π±ΠΎΡΡΠΈΠΊ ΠΊΠ»ΠΈΠΊΠ° ΠΏΠΎ ΠΊΠ½ΠΎΠΏΠΊΠ΅, ΠΊΠ½ΠΎΠΏΠΊΠ° Π½Π°Ρ
ΠΎΠ΄ΠΈΡΡΡ Π²Π½ΡΡΡΠΈ SelectedItemsContains { if (SelectedItemsContains != null) // SelectedItemsContains - Π²ΡΠ±ΡΠ°Π½Π½ΡΠΉ ΡΠ»Π΅ΠΌΠ΅Π½Ρ ΠΊΠΎΠ»Π»Π΅ΠΊΡΠΈΠΈ (ΠΏΡΠΈΠ²ΡΠ·Π°Π½ ΠΊ SelectedIndex). { string connectionString = "SERVER = localhost; DATABASE = root; UID = vbnz; PASSWORD = ;"; MySqlConnection connection = new MySqlConnection(connectionString); MySqlCommand query = new MySqlCommand("UPDATE groups SET userLogin = '-' WHERE id = '" + SelectedItemsContains.CId + "' LIMIT 1", connection); connection.Open(); MySqlDataReader query_result = query.ExecuteReader(); connection.Close(); Cursor = Cursors.Wait; Thread.Sleep(300); Cursor = Cursors.Arrow; SelectedItemsContains.UserLogin = "-"; // Π Π΅ΡΠ΅Π½ΠΈΠ΅ } }
I do not know how correct it is, but it solved the problem.