Reset all Numeric TextBox values inside listview

Hi there 

how I can take the sum of Numeric TextBox values and reset Numeric TextBox values inside listview when click button ?

here is screenshot from mylist . when click save button if the  sum of Numeric TextBoxs values are bigger or less than total price then reset all  Numeric TextBox value to 0 

SEW.png

here is my xaml:



                        <sync:SfListView

                                    x:Name="listView"

                                    Grid.Row="1"

                                    Grid.Column="0"

                                    AutoFitMode="Height"

                                    HorizontalOptions="Start"

                                    ItemSpacing="1"

                                    HeightRequest="300"

                                    SelectionMode="Single"

                                    IsScrollingEnabled="True"

                                    IsScrollBarVisible="True"

                                    ItemTapped="listView_ItemTapped">

                            <sync:SfListView.ItemTemplate>

                                <DataTemplate>

                                    <Frame>

                                        <Grid>

                                            <Grid.ColumnDefinitions>

                                                <ColumnDefinition />

                                                <ColumnDefinition />

                                            </Grid.ColumnDefinitions>

                                            <Label Grid.Row="0"

                                                   Grid.Column="0"

                                                   Text="{Binding PayName}"

                                                   LineBreakMode="WordWrap"

                                                   HorizontalOptions="Start"

                                                   TextColor="Black"

                                                   Padding="5"

                                                    Style="{StaticResource TitleLabelStyle}"

                                                   FontSize="16">


                                            </Label>

                                            <syncfusion:SfNumericTextBox

                                                 HorizontalOptions="End"

                                                Grid.Column="1"

                            x:Name="ValueNumericTextBox"

                            Margin="3,0"

                            HeightRequest="40"

                            WidthRequest="150"

                            Value="{Binding PayValue}"

                           BorderColor="{StaticResource PrimaryColor}"

                                                TextAlignment="Center"

                                                Minimum="0"

                                                ValueChanged="ValueNumericTextBox_ValueChanged_1"

                                                >

                                            </syncfusion:SfNumericTextBox>

                                        </Grid>

                                    </Frame>

                                </DataTemplate>

                            </sync:SfListView.ItemTemplate>


                            <!-- Layout to customize no. of columns in SfListView -->

                            <sync:SfListView.LayoutManager>

                                <sync:GridLayout SpanCount="1" />

                            </sync:SfListView.LayoutManager>

                        </sync:SfListView>





and this the code :

  private void listView_ItemTapped(object sender, Syncfusion.ListView.XForms.ItemTappedEventArgs e)

        {

            var pay = e.ItemData as PayMethod;

            if (pay.PayValue > Totalval)

            {

            Application.Current.MainPage.DisplayAlert("Error ! " , "pay.PayValue bigger than Total \n re-enter correct value less than or equal total value" , "OK");

            }

            else

            {

            Application.Current.MainPage.DisplayAlert("Pay $", "Pay Method : "+ pay.PayName + "\n Pay Value = "+pay.PayValue+ "\n Total = "+Totalval, "OK");

            }

        }


        private void SfButton_Clicked(object sender, EventArgs e)

        {

            if (val>Totalval)

            {

                Application.Current.MainPage.DisplayAlert("Pay $", "The amount paid is greater than the total requested."+"\n Req = "+Totalval +" SR"+"\n Amount paid = "+val+" SR"+"\n Enter a valid value", "OK");

            }

            else if(val<Totalval)

            {

                Application.Current.MainPage.DisplayAlert("Pay $", "The amount paid is less than the total requested." + "\n Req = " + Totalval + " SR" + "\n Amount paid = " + val + " SR" + "\n Enter a valid value", "OK");

            }

            else

            {

                Application.Current.MainPage.DisplayAlert("Pay $", "Payment completed successfully", "OK");

                CloseAllPopup();

                CartPage cartPage = new CartPage();

                App.Current.MainPage = cartPage;

            }

        }

        private void ValueNumericTextBox_ValueChanged_1(object sender, Syncfusion.SfNumericTextBox.XForms.ValueEventArgs e)

        {

            int amount = Int32.Parse(e.Value.ToString());

            val +=amount;

        }


1 Reply

LN Lakshmi Natarajan Syncfusion Team July 27, 2021 10:20 AM UTC

Hi Etawreed, 
 
Thank you for using Syncfusion products. 
 
We have checked the reported query “Reset all Numeric TextBox values inside listview” from our side. We would like to inform you that you update the ListViewItem values at run time. In this case, you can get all the items data from the SfListView.DataSource.DisplayItems and reset the value.  
 
Please refer to the following code snippets for more reference, 
 
Get the items from the DisplayItems and reset the values. 
private void SfButton_Clicked(object sender, EventArgs e) 
{ 
    if (val > Totalval) 
    { 
        Application.Current.MainPage.DisplayAlert("Pay $", "The amount paid is greater than the total requested." + " Req = " + Totalval + " SR" + " Amount paid = " + val + " SR" + " Enter a valid value", "OK"); 
        ResetPayValue(); 
    } 
    else if (val < Totalval) 
    { 
        Application.Current.MainPage.DisplayAlert("Pay $", "The amount paid is less than the total requested." + " Req = " + Totalval + " SR" + " Amount paid = " + val + " SR" + " Enter a valid value", "OK"); 
        ResetPayValue(); 
    } 
    else 
    { 
        Application.Current.MainPage.DisplayAlert("Pay $", "Payment completed successfully", "OK"); 
        CloseAllPopup(); 
        CartPage cartPage = new CartPage(); 
        App.Current.MainPage = cartPage; 
    } 
} 
... 
 
private void ResetPayValue() 
{ 
    var items = listView.DataSource.DisplayItems; 
 
    foreach(Contacts item in items) 
    { 
        item.PayValue = 0; 
    } 
} 
 
 
Note: You need to implement the INotifyPropertyChanged interface and invoke the PropertyChanged event for the Property to update the runtime changes in the UI. 
 
Please refer to the following code snippets for more reference, 
public class Products : INotifyPropertyChanged 
{ 
    ... 
 
    public double PayValue 
    { 
        get { return payValue; } 
        set 
        { 
            if (payValue != value) 
            { 
                payValue = value; 
                this.RaisedOnPropertyChanged("PayValue"); 
            } 
        } 
    } 
 
    public event PropertyChangedEventHandler PropertyChanged; 
 
    public void RaisedOnPropertyChanged(string _PropertyName) 
    { 
        if (PropertyChanged != null) 
        { 
            PropertyChanged(this, new PropertyChangedEventArgs(_PropertyName)); 
        } 
    } 
} 
 
 
 
Please refer to the following documentation regarding the same, 
 
Also, refer to our user guidance document regarding the same, 
 
Please let us know if you need further assistance. 
 
Lakshmi Natarajan 
  
 


Loader.
Up arrow icon