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
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;
}
|
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;
}
} |
|
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));
}
}
} |