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
390
Checkbox Editor Not Binding
posted

In Visual Studio 2008 I have a grid bound to a dataSet BindingSource. A column in the bound dataTable shows strings "YES" or "NO" and I'm using a data filter to convert the values for boolean display in a grid checkbox (the code shown below). Everything works okay except that when the grid fills the checkbox column stays null, while subsequence clicks of checkboxes properly use the data filter and send accurate values to my database. So somehow at start-up the initials values from the data source don't register in the grid checkboxes. Can anyone see my code errors? Thanks in advance for advice.

 

 private void grid_InitializeLayout(object sender, Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs e)
{
         e.Layout.Bands[0].Columns["MYFIELD"].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.CheckBox;
         e.Layout.Bands[0].Columns["MYFIELD"].Editor.DataFilter = new CheckEditorDataFilter();

}

 

        class CheckEditorDataFilter : Infragistics.Win.IEditorDataFilter
        {
            object Infragistics.Win.IEditorDataFilter.Convert(Infragistics.Win.EditorDataFilterConvertArgs args)
            {
                switch (args.Direction)
                {
                    case ConversionDirection.EditorToOwner: // To dataset
                        args.Handled = true;
                        CheckState state = (CheckState)args.Value;
                        switch (state)
                        {
                            case CheckState.Checked:
                                return "YES";
                            case CheckState.Unchecked:
                                return "NO";
                            case CheckState.Indeterminate:
                                return "NO";
                        }
                        break;
                    case ConversionDirection.OwnerToEditor: // To dataset
                        args.Handled = true;
                        if (args.Value.ToString() == "YES")
                            return CheckState.Checked;
                        else if (args.Value.ToString() == "NO")
                            return CheckState.Unchecked;
                        else
                            return CheckState.Indeterminate;
                }
                throw new Exception("Invalid value passed into CheckEditorDataFilter.Convert()");
            }
        }

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Parents
No Data
Reply
  • 37774
    Suggested Answer
    posted

    Are you sure that the case of the values is correct?  For example, are you possibly getting the initial values as "Yes" or "yes" instead of the uppercase "YES" that you're explicitly checking for in the data filter?  You might want to consider calling ToLower() on the string and compare it with "yes" or "no". 

    -Matt

Children
No Data