We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

I want to use sfbutton to create some functions.

Thread ID:

Created:

Updated:

Platform:

Replies:

145141 Jun 10,2019 05:20 AM UTC Jun 14,2019 07:07 AM UTC Xamarin.Forms 5
loading
Tags: SfButton
BN YOO
Asked On June 10, 2019 05:20 AM UTC

Hi. The answer to the previous thread is very appreciated.

I want to use sfbutton to create some functions.

One. If the value of People is 3, then 3 boxes should be selected automatically when selecting Station.
(Naturally, four are selected when four people are selected, and nine are selected when nine people are selected.)

Two. Also, when you look at the attached source, Available Station is one group of 11 ~ 19 and another group of 21 ~ 29. 
If there is an item selected in group 1, grouping function is necessary because it should not be possible to select in group 2. Is it possible?

Three. When SAVE button is clicked, the value of the currently checked value must be transferred to DB.(The checked data(value, ischeked..) must be a DataTable.)

Is it possible to control all the sfbutton in the form?

I am sorry to have many questions. But it is essential for development.


Attached Source

Hemalatha Marikumar [Syncfusion]
Replied On June 12, 2019 02:10 AM UTC

Hi BN YOO,

Thanks for contacting Syncfusion Support.

Query: If the value of People is 3, then 3 boxes should be selected automatically when selecting Station.

We have modified your sample to achieve your requirement. Instead of adding that buttons into StackLayout , we have added that in custom StackLayout with SelectedCount and SelectedItems property. For this query, we have to make the selection of SfButton based on the value of People count. That has been done with the help of  OnChildAdded method of CustomStackLayout

 
 
    int selectedValue = 0;
        protected override void OnChildAdded(Element child)
        {
            if (!string.IsNullOrEmpty(SelectedCount))
            {
                if (selectedValue < int.Parse(SelectedCount))
                {
                    var button = child as SfButton;
                    button.IsChecked = true;
                    selectedValue++;
                    SelectedItems.Add(button);
                }
            }
            base.OnChildAdded(child);
        }
 


Query: If there is an item selected in group 1, grouping function is necessary because it should not be possible to select in group 2. Is it possible?

For that, we have maintained the SelectedItems property of CustomStackLayout. Every SfButton's click, need to ensure whether that has been checked or unchecked. If it is checked then add that SfButton into SelectedItems property of its CustomStackLayout.  And also maintained the different SfButton's click for the second level group. If we select the buttons in the first level, need to check the count of second level CustomStackLayout's SelectedItems property count. If that count is 0, then you can allow to select the items otherwise, disable the first level CustomStackLayout. 
 
  
private void FontButton_Clicked(object sender, System.EventArgs e)
        {
            var sfButton = sender as SfButton;
            if (secondLevelStack.SelectedItems.Count != 0)
            {
                sfButton.IsChecked = false;
                firstLevelStack.IsEnabled = false;
            }
            else
            {
                firstLevelStack.IsEnabled = true;
                if (sfButton.IsChecked && !firstLevelStack.SelectedItems.Contains(sfButton))
                {
                    firstLevelStack.SelectedItems.Add(sfButton);
                }
                if (!sfButton.IsChecked && firstLevelStack.SelectedItems.Contains(sfButton))
                {
                    firstLevelStack.SelectedItems.Remove(sfButton);
                }
                if(firstLevelStack.SelectedItems.Count == 0)
                {
                   secondLevelStack.IsEnabled = true;
                }
            }
        }
 


The same procedure has been done for second level CustomStackLayout.

Query: When SAVE button is clicked, the value of the currently checked value must be transferred to DB.

You can easily get the recently checked button from CustomStackLayout's SelectedItems property. Last hold items must be a recently selected button.

Please download the modified sample link:  http://www.syncfusion.com/downloads/support/forum/145141/ze/StationSample-1214659077

Please check the sample and let us know if you have any concern on this.

Regards,
Hemalatha M. 
 


BN YOO
Replied On June 12, 2019 04:15 AM UTC

Hi. Hemalatha M. 
I'll always remember your kindness.

The second and third questions were resolved
but, The first question will be explained again.

If the value of people is 3, 3 sfbutton should be selected at the same time when the user clicks.
but you refer to the source, you will be automatically selected in the firstLevelStack section.
For example, if a user clicks the sfbutton with a value of 13, the buttons 13, 14, and 15 are automatically clicked.
(With just one click, three buttons are clicked, and the user can no longer click over the button.)

In addition, if you want to load the sfbutton value from the DB according to the order number and make sfbutton true in OnAppearing, what method should be used?

Sorry. Thank you again for your answers once again.

Bharathiraja K [Syncfusion]
Replied On June 12, 2019 01:24 PM UTC

Hi BN YOO, 
 
Thanks for your update. 
 
We have modified the previous sample with an initial click makes the selection of consequence SfButton based on the people count like in below code example. 
 
[C#]: 
 var sfButton = sender as SfButton;
            if (isIntialLoaded)
            {
                var labelCount = int.Parse(txtSelectedREMK.Value.ToString());
                var index =   firstLevelStack.Children.IndexOf(sfButton);
                var total = labelCount + index;
                for (int i = index; i < firstLevelStack.Children.Count && i<total;i++)
                {
                    var initiallyAddedButton = firstLevelStack.Children[i] as SfButton;
                    initiallyAddedButton.IsChecked = true;
                    firstLevelStack.SelectedItems.Add(initiallyAddedButton);
                }
                isIntialLoaded = false;
            }
 
 
That isIntialLoaded value has been enabled on page loading (OnAppearing method) only. 
 
We can't find the exact cases of asking the method to load the SfButton into Database as well as keep clickable of SfButton. We have suggested to use the BeginInvokeOnMainThread OnAppearing Method like in below 
 
[C#]: 
 protected override void OnAppearing()
        {
            base.OnAppearing();
            isIntialLoaded = true;
            // Value from DB
            Device.BeginInvokeOnMainThread(async () =>
            {
                await Task.Delay(200);
                transparentButton.IsCheckable = true;
            });

        }
 
 
 
Note: In your requirement, most of them not related to Button control and it is related to sample level requirement. So, please achieve sample level scenario at your side. If you have any queries, behaviors or issues in button controls, you can contact us. As always, we are happy to assist you. 
 
Regards, 
Bharathi. 


BN YOO
Replied On June 14, 2019 06:49 AM UTC

I'll always remember your kindness.
Thanks to syncfusion support, we have solved all the problems well.

Bharathiraja K [Syncfusion]
Replied On June 14, 2019 07:07 AM UTC

Hi BN YOO,  
 
Thanks for your feedback. We are glad that all your problems resolved at your end. 
  
Regards, 
Bharathi. 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon