Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
985
Get CheckboxColumnValue
posted

Hi there,

 i have a small project with a DataGrid where one field is a CheckBoxColumn.

 i set the CheckBox in the Column with the following Style in code behind:

 

UnboundField checkfield = new UnboundField();

ControlTemplate controltemplate;
string xamlControl = "";

xamlControl = @"
<ControlTemplate xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"" xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"">
<CheckBox HorizontalAlignment=""Center"" IsChecked=""{Binding Attributes[Used]}"" VerticalAlignment=""Center""/>
</ControlTemplate>"; 

 


byte[] xmlControl = Encoding.ASCII.GetBytes(xamlControl);
MemoryStream stream = new MemoryStream(xmlControl);

controltemplate = (ControlTemplate)XamlReader.Load(stream);

Setter templateSetter = new Setter(CellValuePresenter.TemplateProperty, controltemplate);

Style checkboxcell = new Style(typeof(CellValuePresenter));
checkboxcell.Setters.Add(templateSetter);

checkfield.Settings.CellValuePresenterStyle = checkboxcell; 

 

Everything is working fine and now i come to my problem.

 

i need to read every record in the grid  and extract the boolean IsChecked-Value of the CheckBoxColumn for each record.

How do i handle this?

 

regards

Cloud 

Parents
No Data
Reply
  • 985
    posted

    Cloud Strife said:

    Hi there,

     i have a small project with a DataGrid where one field is a CheckBoxColumn.

     i set the CheckBox in the Column with the following Style in code behind:

     

    UnboundField checkfield = new UnboundField();

    ControlTemplate controltemplate;
    string xamlControl = "";

    xamlControl = @"
    <ControlTemplate xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"" xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"">
    <CheckBox HorizontalAlignment=""Center"" IsChecked=""{Binding Attributes[Used]}"" VerticalAlignment=""Center""/>
    </ControlTemplate>"; 

     


    byte[] xmlControl = Encoding.ASCII.GetBytes(xamlControl);
    MemoryStream stream = new MemoryStream(xmlControl);

    controltemplate = (ControlTemplate)XamlReader.Load(stream);

    Setter templateSetter = new Setter(CellValuePresenter.TemplateProperty, controltemplate);

    Style checkboxcell = new Style(typeof(CellValuePresenter));
    checkboxcell.Setters.Add(templateSetter);

    checkfield.Settings.CellValuePresenterStyle = checkboxcell; 

    regards

    Cloud 

     

    i tried another way:

     

    UnboundField checkfield = new UnboundField();

    checkfield.Name = "";
    checkfield.Settings.EditorType = typeof(XamCheckEditor);
    checkfield.Settings.EditAsType = typeof(bool);

    Style editorStyle = new Style(typeof(XamCheckEditor));

    Setter styleSetter = new Setter(XamCheckEditor.IsCheckedProperty, dictionary["Used"]);
    editorStyle.Setters.Add(styleSetter);
    checkfield.Settings.EditorStyle = editorStyle;
    checkfield.Settings.AllowEdit = true;
    checkfield.Width = new FieldLength(50);
    grid.FieldLayouts[0].Fields.Add(checkfield); 

     this works as good as the other way. But now i have the problem that if i want to get the Value of the cell where my checkbox is in, the value is null.

    i noticed that i have to edit one time so that the value of the cell is filled with true or false. but i need that the value is loaded at the first loading of the window.

     

    please help me asap

     

    regards

    cloud 

Children