Own StyleModel with DataBinding

Posted by: vkubalek on 8 September 2017, 2:45 pm EST

  • Posted 8 September 2017, 2:45 pm EST

    Can you help me with this simple code? It shows red cross. How can I use my own StyleModel with DataBinding?
     
    tasks is type of List 
     
        ...
        //create data model
                var data = fpSpread1_Sheet1.Models.Data as FarPoint.Win.Spread.Model.DefaultSheetDataModel;
                data.DataSource = tasks;

                //create style model
                var style = new TaskStyleModel();
                fpSpread1_Sheet1.Models.Style = style;
                ... 
     
     TaskStyleModel is just derived from DefaultSheetStyleModel
     public class TaskStyleModel : DefaultSheetStyleModel
        {       
        }
     
    Thank you
    Vladislav 
  • Replied 8 September 2017, 2:45 pm EST

    Hello,

    I would suggest you to post us a sample depicting your issue, so that I can look into the implementation of the approach that you have followed. It would help me to investigate the issue further and provide you with a solution.

    Thanks,

    Manpreet Kaur.

  • Replied 8 September 2017, 2:45 pm EST

    Hello,

    I was able to replicate the issue at my end. I would like you to know that Spread is made of five underlying models, out of which StyleModel is one model, when you define a custom Style Model, you are not specifying any number of rows or columns on which to apply the style, so it creates a model with zero rows and zero columns , however the DataModel still has default number of rows and default number of columns, which causes the models to get out of sync.





    pre.western { font-family: "Liberation Serif"; }pre.cjk { font-family: "DejaVu Sans",monospace; }p { margin-bottom: 0.21cm; }If the models get out of sync, then index out-of-range exceptions can be caused by code trying to get information about nonexistent rows or columns. So, I have modified your sample and defined a new constructor in the custom Style model that takes the Data Model rows and columns as argument and hence resolves the issue. Please have a look at the sample.

    Hope it will help you.

    Thanks,

    Manpreet Kaur


    2011/09/WindowsFormsApplication1-3.zip
  • Replied 8 September 2017, 2:45 pm EST

    Thank you, it works.

    How can I keep Coulmn and Row Count fresh anytime?

    Can I override these properties this way in StyleModel?

     public override int RowCount

            {

           get 

           {

                    return DataModel.RowCount;

           }

            }

     

    Next question. Is there a way to find out what caused the Red Cross?

     For example now I have red cross with this "nice" message and I have no idea what's wrong in code.

     

    See the end of this message for details on invoking 

    just-in-time (JIT) debugging instead of this dialog box.


    ************** Exception Text **************

    System.Exception: Exception handled in FpSpread.WndProc ---> System.Exception: Exception handled in FpSpread.OnPaint() ---> System.NullReferenceException: Object reference not set to an instance of an object.

       at FarPoint.Win.Spread.SpreadView.e(Graphics A_0)

       at FarPoint.Win.Spread.SpreadView.g(Graphics A_0)

       at FarPoint.Win.Spread.FpSpread.OnPaint(PaintEventArgs e)

       --- End of inner exception stack trace ---

       at FarPoint.Win.Spread.FpSpread.OnPaint(PaintEventArgs e)

       at System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer, Boolean disposeEventArgs)

       at System.Windows.Forms.Control.WmPaint(Message& m)

       at System.Windows.Forms.Control.WndProc(Message& m)

       at FarPoint.Win.Spread.FpSpread.WndProc(Message& m)

       --- End of inner exception stack trace ---

       at FarPoint.Win.Spread.FpSpread.WndProc(Message& m)

       at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)

       at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)

       at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)



    ************** Loaded Assemblies **************

    mscorlib

        Assembly Version: 2.0.0.0

        Win32 Version: 2.0.50727.3623 (GDR.050727-3600)

        CodeBase: file:///C:/WINDOWS/Microsoft.NET/Framework/v2.0.50727/mscorlib.dll

    ----------------------------------------

    Microsoft.VisualStudio.HostingProcess.Utilities

        Assembly Version: 9.0.0.0

        Win32 Version: 9.0.21022.8

        CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/Microsoft.VisualStudio.HostingProcess.Utilities/9.0.0.0__b03f5f7f11d50a3a/Microsoft.VisualStudio.HostingProcess.Utilities.dll

    ----------------------------------------

    System.Windows.Forms

        Assembly Version: 2.0.0.0

        Win32 Version: 2.0.50727.3623 (GDR.050727-3600)

        CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Windows.Forms/2.0.0.0__b77a5c561934e089/System.Windows.Forms.dll

    ----------------------------------------

    System

        Assembly Version: 2.0.0.0

        Win32 Version: 2.0.50727.3624 (GDR.050727-3600)

        CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System/2.0.0.0__b77a5c561934e089/System.dll

    ----------------------------------------

    System.Drawing

        Assembly Version: 2.0.0.0

        Win32 Version: 2.0.50727.3053 (netfxsp.050727-3000)

        CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Drawing/2.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll

    ----------------------------------------

    Microsoft.VisualStudio.HostingProcess.Utilities.Sync

        Assembly Version: 9.0.0.0

        Win32 Version: 9.0.21022.8

        CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/Microsoft.VisualStudio.HostingProcess.Utilities.Sync/9.0.0.0__b03f5f7f11d50a3a/Microsoft.VisualStudio.HostingProcess.Utilities.Sync.dll

    ----------------------------------------

    Microsoft.VisualStudio.Debugger.Runtime

        Assembly Version: 9.0.0.0

        Win32 Version: 9.0.21022.8

        CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/Microsoft.VisualStudio.Debugger.Runtime/9.0.0.0__b03f5f7f11d50a3a/Microsoft.VisualStudio.Debugger.Runtime.dll

    ----------------------------------------

    vshost

        Assembly Version: 9.0.0.0

        Win32 Version: 9.0.21022.8

        CodeBase: file:///C:/idc/trunk_/TaskQueue/bin/Debug/TaskQueue.vshost.exe

    ----------------------------------------

    FarPoint.CalcEngine

        Assembly Version: 5.0.2003.2008

        Win32 Version: 5.0.2003.2008

        CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/FarPoint.CalcEngine/5.0.2003.2008__327c3516b1b18457/FarPoint.CalcEngine.dll

    ----------------------------------------

    FarPoint.Excel

        Assembly Version: 5.0.2003.2008

        Win32 Version: 5.0.2003.2008

        CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/FarPoint.Excel/5.0.2003.2008__327c3516b1b18457/FarPoint.Excel.dll

    ----------------------------------------

    FarPoint.PDF

        Assembly Version: 1.0.2023.2005

        Win32 Version: 1.0.2023.2005

        CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/FarPoint.PDF/1.0.2023.2005__327c3516b1b18457/FarPoint.PDF.dll

    ----------------------------------------

    FarPoint.PluginCalendar.WinForms

        Assembly Version: 5.0.2003.2008

        Win32 Version: 5.0.2003.2008

        CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/FarPoint.PluginCalendar.WinForms/5.0.2003.2008__327c3516b1b18457/FarPoint.PluginCalendar.WinForms.dll

    ----------------------------------------

    FarPoint.Win

        Assembly Version: 5.0.2003.2008

        Win32 Version: 5.0.2003.2008

        CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/FarPoint.Win/5.0.2003.2008__327c3516b1b18457/FarPoint.Win.dll

    ----------------------------------------

    FarPoint.Win.Chart

        Assembly Version: 1.0.2003.2008

        Win32 Version: 1.0.2003.2008

        CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/FarPoint.Win.Chart/1.0.2003.2008__327c3516b1b18457/FarPoint.Win.Chart.dll

    ----------------------------------------

    FarPoint.Win.Spread

        Assembly Version: 5.0.2003.2008

        Win32 Version: 5.0.2003.2008

        CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/FarPoint.Win.Spread/5.0.2003.2008__327c3516b1b18457/FarPoint.Win.Spread.dll

    ----------------------------------------

    System.Core

        Assembly Version: 3.5.0.0

        Win32 Version: 3.5.30729.1 built by: SP

        CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Core/3.5.0.0__b77a5c561934e089/System.Core.dll

    ----------------------------------------

    System.Design

        Assembly Version: 2.0.0.0

        Win32 Version: 2.0.50727.3053 (netfxsp.050727-3000)

        CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Design/2.0.0.0__b03f5f7f11d50a3a/System.Design.dll

    ----------------------------------------

    System.EnterpriseServices

        Assembly Version: 2.0.0.0

        Win32 Version: 2.0.50727.3053 (netfxsp.050727-3000)

        CodeBase: file:///C:/WINDOWS/assembly/GAC_32/System.EnterpriseServices/2.0.0.0__b03f5f7f11d50a3a/System.EnterpriseServices.dll

    ----------------------------------------

    System.Runtime.Serialization

        Assembly Version: 3.0.0.0

        Win32 Version: 3.0.4506.3636 (GDR.030729-3600)

        CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Runtime.Serialization/3.0.0.0__b77a5c561934e089/System.Runtime.Serialization.dll

    ----------------------------------------

    System.ServiceModel

        Assembly Version: 3.0.0.0

        Win32 Version: 3.0.4506.3636 (GDR.030729-3600)

        CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.ServiceModel/3.0.0.0__b77a5c561934e089/System.ServiceModel.dll

    ----------------------------------------

    System.Web

        Assembly Version: 2.0.0.0

        Win32 Version: 2.0.50727.3618 (GDR.050727-3600)

        CodeBase: file:///C:/WINDOWS/assembly/GAC_32/System.Web/2.0.0.0__b03f5f7f11d50a3a/System.Web.dll

    ----------------------------------------

    System.Web.Services

        Assembly Version: 2.0.0.0

        Win32 Version: 2.0.50727.3053 (netfxsp.050727-3000)

        CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Web.Services/2.0.0.0__b03f5f7f11d50a3a/System.Web.Services.dll

    ----------------------------------------

    System.Xml.Linq

        Assembly Version: 3.5.0.0

        Win32 Version: 3.5.30729.1 built by: SP

        CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Xml.Linq/3.5.0.0__b77a5c561934e089/System.Xml.Linq.dll

    ----------------------------------------

    System.Data.DataSetExtensions

        Assembly Version: 3.5.0.0

        Win32 Version: 3.5.30729.1 built by: SP

        CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Data.DataSetExtensions/3.5.0.0__b77a5c561934e089/System.Data.DataSetExtensions.dll

    ----------------------------------------

    System.Data

        Assembly Version: 2.0.0.0

        Win32 Version: 2.0.50727.3053 (netfxsp.050727-3000)

        CodeBase: file:///C:/WINDOWS/assembly/GAC_32/System.Data/2.0.0.0__b77a5c561934e089/System.Data.dll

    ----------------------------------------

    System.Deployment

        Assembly Version: 2.0.0.0

        Win32 Version: 2.0.50727.3053 (netfxsp.050727-3000)

        CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Deployment/2.0.0.0__b03f5f7f11d50a3a/System.Deployment.dll

    ----------------------------------------

    System.Xml

        Assembly Version: 2.0.0.0

        Win32 Version: 2.0.50727.3082 (QFE.050727-3000)

        CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Xml/2.0.0.0__b77a5c561934e089/System.Xml.dll

    ----------------------------------------

    WindowsBase

        Assembly Version: 3.0.0.0

        Win32 Version: 3.0.6920.4016 built by: GDR

        CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/WindowsBase/3.0.0.0__31bf3856ad364e35/WindowsBase.dll

    ----------------------------------------

    TaskQueue

        Assembly Version: 1.0.0.0

        Win32 Version: 1.0.0.0

        CodeBase: file:///C:/idc/trunk_/TaskQueue/bin/Debug/TaskQueue.EXE

    ----------------------------------------

    System.Configuration

        Assembly Version: 2.0.0.0

        Win32 Version: 2.0.50727.3053 (netfxsp.050727-3000)

        CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Configuration/2.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll

    ----------------------------------------

    gmbg9kuh

        Assembly Version: 1.0.0.0

        Win32 Version: 2.0.50727.3624 (GDR.050727-3600)

        CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System/2.0.0.0__b77a5c561934e089/System.dll

    ----------------------------------------


    ************** JIT Debugging **************

    To enable just-in-time (JIT) debugging, the .config file for this

    application or computer (machine.config) must have the

    jitDebugging value set in the system.windows.forms section.

    The application must also be compiled with debugging

    enabled.


    For example:


       


    When JIT debugging is enabled, any unhandled exception

    will be sent to the JIT debugger registered on the computer

    rather than be handled by this dialog box.



     

  • Replied 8 September 2017, 2:45 pm EST

    Hello,

    1. I don't think this would be the correct way to refresh the RowCount and ColumnCount. Once you have applied the StyleModel to the Spread, you can reset the RowCount and ColumnCount simply by accessing the RowCount and ColumnCount propertis of the SheetView. Can you please elaborate the scenario in which you are trying to refresh the RowCount and ColumnCount.

    2. The reason for the Red Cross in the former case was the asynchronization in the RowCount and ColumnCount of the StyleModel and DataModel, by default the DataModel has some fixed number of rows and columns, when you create a new StyleModel without any values for the RowCount and ColumnCount, it creates a model with zero rows and zero columns leading to a mismatch in the RowCount and ColumnCount of the two models. I would again need a sample depicting your issue to provide you with a solution for the red cross that you are getting now.

    Thanks,

    Manpreet Kaur.

  • Replied 8 September 2017, 2:45 pm EST

    Hello, 

      DataModel has set DataSource = some BindingList or DataTable or whatever. And this DataSource is dynamicaly modified of course. The question is how to sync StyleModel.RowCount and ColumnCount with the DataSource?

  • Replied 8 September 2017, 2:45 pm EST

    Sample project - farpoint libraries not included

    Farpoint.Win.Spread version 5.0.2003.2008 


    2011/09/WindowsFormsApplication1-2.zip
  • Replied 8 September 2017, 2:45 pm EST

    Hello,

    I would like you to know that once the datasource is modified, you would need to reset the Spread, and again set its datasource to the modified datasource. Once you reset the datasource of Spread all the models are reset to the Default models in Spread. So, you would need to again set the style model for the Spread, which would automatically make the RowCount and Columncount to be synchronized in both the models.

    I have created a sample depicting the same, please follow the following steps to execute the sample:

    1. Run the sample. It would load a list into the Spread and apply the Style model, the Style model colors the row with value "test3", in dark red color, indicating style model is applied.

    2. Click on the "Modify datasource" button, this would add some more items to the list.

    3. Click on the "Reset datasource and style model" button, this would make the modified datasource to be applied to the Spread along with the Style model, which sets the rows with value "test3" or test6", dark red in color, indicating that style model is again applied to Spread.

    Kindly have a look at the sample. Please let me know if you have any queries further.

    Hope it will help you.

    Thanks,

    Manpreet Kaur.


    2011/09/WindowsFormsApplication1-4.zip
Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels