Frage

I am a beginner in programming. I want to manage my Checkbox by including "if-else-condition" in it. For examples, there are two columns in my grid which are named "readable" and "writable" (public bool). I will use CheckBox for these two columns.

1) the CheckBox will be "read-only", if the value of readable/writable is false.

2) the CheckBox are editable by the user, if the value of readable/writable is true.

For example, how can I edit from the code below? (assuming that I have done my data-binding)

<sf:GridTreeColumn MappingName="Readable" PercentWidth="2">
    <sf:GridTreeColumn.StyleInfo>
        <sf:GridStyleInfo CellType="CheckBox" HorizontalAlignment="Center" IsThreeState="False"/>
    </sf:GridTreeColumn.StyleInfo>
</sf:GridTreeColumn>
<sf:GridTreeColumn MappingName="Writable" PercentWidth="2">
    <sf:GridTreeColumn.StyleInfo>
        <sf:GridStyleInfo CellType="CheckBox" HorizontalAlignment="Center" IsThreeState="False"/>
    </sf:GridTreeColumn.StyleInfo>
</sf:GridTreeColumn>

Sincere thanks to all who try to read my question and try to help me. =)

War es hilfreich?

Lösung

If you are using Syncfusion controls you have a property get it from syncfusion.GridCommon.wpf. to set check box inside your column

<sf:GridTreeColumn MappingName="Readable" PercentWidth="2">
<sf:GridTreeColumn.StyleInfo>
    <sf:GridStyleInfo CellType="CheckBox" gridCommon:VisualContainer.WantsMouseInput=true HorizontalAlignment="Center" IsThreeState="False"/>
</sf:GridTreeColumn.StyleInfo>

Try this!

Andere Tipps

This can be easily achieved by using the convertes: Add this class in your project and include it in your XAML code

 public sealed class BoolToVisibilityConverter : IValueConverter
{
    #region Methods

    public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {

        bool boolValue = false;

        if (!bool.TryParse(System.Convert.ToString(value), out boolValue))
        {
            boolValue = false;
        }

        if (boolValue)
        {
            return true;
        }
        else
        {
            return false;
        }
    }


    #endregion


    public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        throw new NotImplementedException();
    }
}

XAML Code:

<UserControl.Resources>
    <converter:BoolToVisibilityConverter x:Key="BoolToVisibilityConverter" />
</UserControl.Resources>

<sf:GridTreeColumn MappingName="Readable" PercentWidth="2">
<sf:GridTreeColumn.StyleInfo>
    <sf:GridStyleInfo CellType="CheckBox" HorizontalAlignment="Center"   
 IsThreeState="False" IsEnabled="{Binding Readable, Converter={StaticResource  
 BoolToVisibilityConverter}}"/>
 </sf:GridTreeColumn.StyleInfo>
 </sf:GridTreeColumn>
 <sf:GridTreeColumn MappingName="Writable" PercentWidth="2">
 <sf:GridTreeColumn.StyleInfo>
 <sf:GridStyleInfo CellType="CheckBox" HorizontalAlignment="Center" 

 IsThreeState="False" IsEnabled="{Binding Writable, Converter={StaticResource   
 BoolToVisibilityConverter}}"/>
 </sf:GridTreeColumn.StyleInfo>
 </sf:GridTreeColumn>

Hope this helps.

Although this does not directly answer your question, enabling and disabling the checkbox on button clicks may give you the desired outcome of having the ability to make the checkbox either read only or read/write.

(Note: This simple, yet effective concept can be altered and used in loading events or authentication of users, disabling or enabling particular pieces of content on an application, which may be useful to you in the future.)

        private void btnEnable_Click(object sender, RoutedEventArgs e)
        {
            checkBox.IsEnabled = true;
        }

        private void btnDisable_Click(object sender, RoutedEventArgs e)
        {
            checkBox.IsEnabled = false;
        }
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top