Quantcast
Channel: Our ComponentOne » All Posts
Viewing all articles
Browse latest Browse all 14170

Reply To: C1DataGrid bind custom UserControls

$
0
0

Hi,

I resolved a part of my issue. I can see my user controls in the cells but CreateCellContent event is not always called for each rows. I don’t understand why???

Here my DataGrid code :

<c1:C1DataGrid Height="300" Name="DataGridBibliotheque" ItemsSource="{Binding Path=BibliothequeBoxList}" CanUserAddRows="False" CanUserEditRows="False" CanUserRemoveRows="False"  CanUserReorderColumns="False" CanUserResizeColumns="False" CanUserResizeRows="False" SelectionMode="SingleRow" GroupRowHeight="60px" RowHeight="60px" RowHeaderWidth="40" AutoGeneratedColumns="C1DataGrid_AutoGeneratedColumnsBibliotheque">
                                        <c1:C1DataGrid.Columns>
                                            <Custom:BibliothequeControlsColumn Header="Visuel" IsReadOnly="True" HorizontalAlignment="Center"  VerticalAlignment="Center" IsSelectable="False"></Custom:BibliothequeControlsColumn>
                                        </c1:C1DataGrid.Columns>
                                    </c1:C1DataGrid>

My BibliothequeBoxObject code

public class BibliothequeBoxObject : ObservableObject
    {
        public BibliothequeBoxObjectName Nom { get; set; }
        public BibliothequeBoxObjectType Type { get; set; }
    }

    public enum BibliothequeBoxObjectName
    {
        Object1,
        Object2,
        Object3,
        Object4,
        Object5,
        Object6,
        Object7,
        Object8,
        Object9,
        Object10,
        Object11
    }

    public enum BibliothequeBoxObjectType
    {
        Type1,
        Type2
    }

My DataService code:

public void GetBibliothequeBoxData(Action<ObservableCollection<BibliothequeBoxObject>, Exception> callback)
        {
            var data = new ObservableCollection<BibliothequeBoxObject>();
            data.Add(new BibliothequeBoxObject() { Nom = BibliothequeBoxObjectName.Object1, Type = BibliothequeBoxObjectType.Type1 });
            data.Add(new BibliothequeBoxObject() { Nom = BibliothequeBoxObjectName.Object2, Type = BibliothequeBoxObjectType.Type1 });
            data.Add(new BibliothequeBoxObject() { Nom = BibliothequeBoxObjectName.Object3, Type = BibliothequeBoxObjectType.Type1 });
            data.Add(new BibliothequeBoxObject() { Nom = BibliothequeBoxObjectName.Object4, Type = BibliothequeBoxObjectType.Type1 });
            data.Add(new BibliothequeBoxObject() { Nom = BibliothequeBoxObjectName.Object5, Type = BibliothequeBoxObjectType.Type1 });
            data.Add(new BibliothequeBoxObject() { Nom = BibliothequeBoxObjectName.Object6, Type = BibliothequeBoxObjectType.Type1 });
            data.Add(new BibliothequeBoxObject() { Nom = BibliothequeBoxObjectName.Object7, Type = BibliothequeBoxObjectType.Type1 });
            data.Add(new BibliothequeBoxObject() { Nom = BibliothequeBoxObjectName.Object8, Type = BibliothequeBoxObjectType.Type2 });
            data.Add(new BibliothequeBoxObject() { Nom = BibliothequeBoxObjectName.Object9, Type = BibliothequeBoxObjectType.Type2 });
            data.Add(new BibliothequeBoxObject() { Nom = BibliothequeBoxObjectName.Object10, Type = BibliothequeBoxObjectType.Type2 });
            data.Add(new BibliothequeBoxObject() { Nom = BibliothequeBoxObjectName.Object11, Type = BibliothequeBoxObjectType.Type2 });

            callback(data, null);
        }

And my custom column code:

public class BibliothequeControlsColumn : DataGridBoundColumn
    {
        public override FrameworkElement CreateCellContent(DataGridRow row)
        {
            switch (((BibliothequeBoxObject)row.DataItem).Nom)
            {
                case DragAndScript.Model.BibliothequeBoxObjectName.Oject1: return new Oject1();
                case DragAndScript.Model.BibliothequeBoxObjectName.Oject2: return new Oject2();
                case DragAndScript.Model.BibliothequeBoxObjectName.Oject3: return new Oject3();
                case DragAndScript.Model.BibliothequeBoxObjectName.Oject4: return new Oject4();
                case DragAndScript.Model.BibliothequeBoxObjectName.Oject5: return new Oject5();
                case DragAndScript.Model.BibliothequeBoxObjectName.Oject6: return new Oject6();
                case DragAndScript.Model.BibliothequeBoxObjectName.Oject7: return new Oject7();
                case DragAndScript.Model.BibliothequeBoxObjectName.Oject8: return new Oject8();
                case DragAndScript.Model.BibliothequeBoxObjectName.Oject9: return new Oject9();
                case DragAndScript.Model.BibliothequeBoxObjectName.Oject10: return new Oject10();
                case DragAndScript.Model.BibliothequeBoxObjectName.Oject11: return new Oject11();
                default: return null;
            }
        }
        public override object GetCellContentRecyclingKey(DataGridRow row)
        {
            return typeof(DeviceControl);
        }
        public override void BindCellContent(FrameworkElement cellContent, DataGridRow row)
        {
            //var hyperlink = (DeviceControl)cellContent;
            //if (Binding != null)
            //{
            //    var newBinding = CopyBinding(Binding);
            //    newBinding.Source = row.DataItem;
            //    //hyperlink.SetBinding(DeviceControl, newBinding);
            //    hyperlink.HorizontalAlignment = HorizontalAlignment;
            //    hyperlink.VerticalAlignment = VerticalAlignment;
            //}
        }
        public string TargetName { get; set; }

The result that i have on my datagrid is:
Oject1(xaml)/Oject1(string)
Oject2(xaml)/Oject2(string)
Oject3(xaml)/Oject3(string)
Oject4(xaml)/Oject4(string)
Oject5(xaml)/Oject5(string)
Oject6(xaml)/Oject1(string)
Oject7(xaml)/Oject2(string)
Oject8(xaml)/Oject3(string)
Oject9(xaml)/Oject4(string)
Oject10(xaml)/Oject5(string)
Oject11(xaml)/Oject1(string)

Why i don’t have Oject6(xaml)/Oject6(string),…
If i put a breakpoint to CreateCellContent event, it only enter for the first 5 rows!

Regards,


Viewing all articles
Browse latest Browse all 14170

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>