3

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. =)

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
user3481276
  • 89
  • 10

3 Answers3

2

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!

Ravi Shankar B
  • 472
  • 2
  • 4
  • 15
  • What does "gridCommon:VisualContainer.WantsMouseInput" mean? – user3481276 Mar 31 '14 at 15:03
  • Are you using syncfusion(third party) controls for GridTree?? – Ravi Shankar B Mar 31 '14 at 15:10
  • I see.. Syncfusion means third party. Yea i added Syncfusion to my reference and use it in my xaml codes. Sorry im currently a student and still new to it. =( – user3481276 Mar 31 '14 at 15:12
  • In Syncfusion common dll they provide the API for your requirement, that's I am explaining in this answer. – Ravi Shankar B Mar 31 '14 at 15:13
  • You need to add the namespace for the Syncfusion.GridCommon.Wpf.dll as gridCommon in xaml and you can access the VisualContainer.WantsMouseInput and set it as true for get your requirement. – Ravi Shankar B Mar 31 '14 at 15:14
  • I got what you meant now, gridCommon is the name I gave to the namespace I have added. – user3481276 Mar 31 '14 at 15:16
  • Hi Ravi, adding "xmlns:gridCommon="clr-namespace:Syncfusion.GridCommon.Wpf.dll" is correct right? I have two errors during compilation 1) The name "VisualContainer" does not exist in the namespace "*as stated*". 2) The attachable property 'WantsMouseInput' was not found in type 'VisualContainer'. Thank you so much for your time again. – user3481276 Mar 31 '14 at 15:31
  • you can refer this by accessing this site http://help.syncfusion.com/cr/cref_files/wpf/grid/html/82af5bcd-a08c-42a7-1e4a-a6d0115c484a.htm – Ravi Shankar B Mar 31 '14 at 15:46
  • Check once the Syncfusion.GridCommon.Wpf dll is attached with your project – Ravi Shankar B Mar 31 '14 at 15:48
  • If you feel this as answer please mark it as answer – Ravi Shankar B Mar 31 '14 at 15:59
1

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.

Praveena
  • 78
  • 4
  • Hey Praveena, your idea of converter sounds cool. I'm currently trying this. But, "IsEnabled is not recognised or is not accessible". Perhaps is something miss out? – user3481276 Mar 31 '14 at 15:10
  • It stated "The Property 'IsEnabled' was not found in type 'GridStyleInfo'" – user3481276 Mar 31 '14 at 15:20
  • Hi, I am not familiar with the sync fusion controls, just figure out what is the equivalent of IsEnabled for your control and use it instead. Let me know if it works for you. – Praveena May 15 '14 at 19:27
1

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