Own StyleModel with DataBinding

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

  • Posted 8 September 2017, 2:45 pm EST

    <div>Can you help me with this simple code? It shows red cross. How can I use my own StyleModel with DataBinding?</div><div> </div><div>tasks is type of List<whatever> </div><div> </div><div><span class="Apple-tab-span" style="white-space:pre;"> </span>    ...</div><div><span class="Apple-tab-span" style="white-space:pre;"> </span>    //create data model</div><div>            var data = fpSpread1_Sheet1.Models.Data as FarPoint.Win.Spread.Model.DefaultSheetDataModel;</div><div>            data.DataSource = tasks;</div><div><br></div><div>            //create style model</div><div>            var style = new TaskStyleModel();</div><div>            fpSpread1_Sheet1.Models.Style = style;</div><div>            ... </div><div> </div><div> TaskStyleModel is just derived from DefaultSheetStyleModel</div><div> public class TaskStyleModel : DefaultSheetStyleModel</div><div>    {       </div><div>    }</div><div> </div><div>Thank you</div><div>Vladislav </div>
  • Replied 8 September 2017, 2:45 pm EST

    <p>Hello,</p><p>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.</p><p>Thanks,</p><p>Manpreet Kaur. <br></p>
  • Replied 8 September 2017, 2:45 pm EST

    <p>Hello,</p><p>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.</p><p>Hope it will help you.</p><p>Thanks,</p><p>Manpreet Kaur <br></p>
    2011/09/WindowsFormsApplication1-3.zip
  • Replied 8 September 2017, 2:45 pm EST

    <p>Thank you, it works.</p><p>How can I keep Coulmn and Row Count fresh anytime?</p><p>Can I override these properties this way in StyleModel?</p><p> public override int RowCount</p><p>        {</p><p><span class="Apple-tab-span" style="white-space:pre;"> </span>        get </p><p><span class="Apple-tab-span" style="white-space:pre;"> </span>        {</p><p><span class="Apple-style-span">                return DataModel.</span>RowCount<span class="Apple-style-span">;</span></p><p><span class="Apple-tab-span" style="white-space:pre;"> </span>        }</p><p>        }</p><p> </p><p><span class="Apple-style-span" style="font-family:arial, sans-serif;font-size:13px;line-height:18px;">Next question. Is </span><span class="Apple-style-span" style="font-family:arial, sans-serif;line-height:18px;">there </span><span class="Apple-style-span" style="font-family:arial, sans-serif;line-height:18px;">a way to find out what caused the Red Cross?</span></p><p> For example now I have red cross with this "nice" message and I have no idea what's wrong in code.</p><p> </p><p>See the end of this message for details on invoking </p><p>just-in-time (JIT) debugging instead of this dialog box.</p><p><br></p><p>************** Exception Text **************</p><p>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.</p><p>   at FarPoint.Win.Spread.SpreadView.e(Graphics A_0)</p><p>   at FarPoint.Win.Spread.SpreadView.g(Graphics A_0)</p><p>   at FarPoint.Win.Spread.FpSpread.OnPaint(PaintEventArgs e)</p><p>   --- End of inner exception stack trace ---</p><p>   at FarPoint.Win.Spread.FpSpread.OnPaint(PaintEventArgs e)</p><p>   at System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer, Boolean disposeEventArgs)</p><p>   at System.Windows.Forms.Control.WmPaint(Message& m)</p><p>   at System.Windows.Forms.Control.WndProc(Message& m)</p><p>   at FarPoint.Win.Spread.FpSpread.WndProc(Message& m)</p><p>   --- End of inner exception stack trace ---</p><p>   at FarPoint.Win.Spread.FpSpread.WndProc(Message& m)</p><p>   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)</p><p>   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)</p><p>   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)</p><p><br></p><p><br></p><p>************** Loaded Assemblies **************</p><p>mscorlib</p><p>    Assembly Version: 2.0.0.0</p><p>    Win32 Version: 2.0.50727.3623 (GDR.050727-3600)</p><p>    CodeBase: file:///C:/WINDOWS/Microsoft.NET/Framework/v2.0.50727/mscorlib.dll</p><p>----------------------------------------</p><p>Microsoft.VisualStudio.HostingProcess.Utilities</p><p>    Assembly Version: 9.0.0.0</p><p>    Win32 Version: 9.0.21022.8</p><p>    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/Microsoft.VisualStudio.HostingProcess.Utilities/9.0.0.0__b03f5f7f11d50a3a/Microsoft.VisualStudio.HostingProcess.Utilities.dll</p><p>----------------------------------------</p><p>System.Windows.Forms</p><p>    Assembly Version: 2.0.0.0</p><p>    Win32 Version: 2.0.50727.3623 (GDR.050727-3600)</p><p>    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Windows.Forms/2.0.0.0__b77a5c561934e089/System.Windows.Forms.dll</p><p>----------------------------------------</p><p>System</p><p>    Assembly Version: 2.0.0.0</p><p>    Win32 Version: 2.0.50727.3624 (GDR.050727-3600)</p><p>    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System/2.0.0.0__b77a5c561934e089/System.dll</p><p>----------------------------------------</p><p>System.Drawing</p><p>    Assembly Version: 2.0.0.0</p><p>    Win32 Version: 2.0.50727.3053 (netfxsp.050727-3000)</p><p>    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Drawing/2.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll</p><p>----------------------------------------</p><p>Microsoft.VisualStudio.HostingProcess.Utilities.Sync</p><p>    Assembly Version: 9.0.0.0</p><p>    Win32 Version: 9.0.21022.8</p><p>    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/Microsoft.VisualStudio.HostingProcess.Utilities.Sync/9.0.0.0__b03f5f7f11d50a3a/Microsoft.VisualStudio.HostingProcess.Utilities.Sync.dll</p><p>----------------------------------------</p><p>Microsoft.VisualStudio.Debugger.Runtime</p><p>    Assembly Version: 9.0.0.0</p><p>    Win32 Version: 9.0.21022.8</p><p>    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/Microsoft.VisualStudio.Debugger.Runtime/9.0.0.0__b03f5f7f11d50a3a/Microsoft.VisualStudio.Debugger.Runtime.dll</p><p>----------------------------------------</p><p>vshost</p><p>    Assembly Version: 9.0.0.0</p><p>    Win32 Version: 9.0.21022.8</p><p>    CodeBase: file:///C:/idc/trunk_/TaskQueue/bin/Debug/TaskQueue.vshost.exe</p><p>----------------------------------------</p><p>FarPoint.CalcEngine</p><p>    Assembly Version: 5.0.2003.2008</p><p>    Win32 Version: 5.0.2003.2008</p><p>    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/FarPoint.CalcEngine/5.0.2003.2008__327c3516b1b18457/FarPoint.CalcEngine.dll</p><p>----------------------------------------</p><p>FarPoint.Excel</p><p>    Assembly Version: 5.0.2003.2008</p><p>    Win32 Version: 5.0.2003.2008</p><p>    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/FarPoint.Excel/5.0.2003.2008__327c3516b1b18457/FarPoint.Excel.dll</p><p>----------------------------------------</p><p>FarPoint.PDF</p><p>    Assembly Version: 1.0.2023.2005</p><p>    Win32 Version: 1.0.2023.2005</p><p>    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/FarPoint.PDF/1.0.2023.2005__327c3516b1b18457/FarPoint.PDF.dll</p><p>----------------------------------------</p><p>FarPoint.PluginCalendar.WinForms</p><p>    Assembly Version: 5.0.2003.2008</p><p>    Win32 Version: 5.0.2003.2008</p><p>    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/FarPoint.PluginCalendar.WinForms/5.0.2003.2008__327c3516b1b18457/FarPoint.PluginCalendar.WinForms.dll</p><p>----------------------------------------</p><p>FarPoint.Win</p><p>    Assembly Version: 5.0.2003.2008</p><p>    Win32 Version: 5.0.2003.2008</p><p>    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/FarPoint.Win/5.0.2003.2008__327c3516b1b18457/FarPoint.Win.dll</p><p>----------------------------------------</p><p>FarPoint.Win.Chart</p><p>    Assembly Version: 1.0.2003.2008</p><p>    Win32 Version: 1.0.2003.2008</p><p>    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/FarPoint.Win.Chart/1.0.2003.2008__327c3516b1b18457/FarPoint.Win.Chart.dll</p><p>----------------------------------------</p><p>FarPoint.Win.Spread</p><p>    Assembly Version: 5.0.2003.2008</p><p>    Win32 Version: 5.0.2003.2008</p><p>    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/FarPoint.Win.Spread/5.0.2003.2008__327c3516b1b18457/FarPoint.Win.Spread.dll</p><p>----------------------------------------</p><p>System.Core</p><p>    Assembly Version: 3.5.0.0</p><p>    Win32 Version: 3.5.30729.1 built by: SP</p><p>    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Core/3.5.0.0__b77a5c561934e089/System.Core.dll</p><p>----------------------------------------</p><p>System.Design</p><p>    Assembly Version: 2.0.0.0</p><p>    Win32 Version: 2.0.50727.3053 (netfxsp.050727-3000)</p><p>    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Design/2.0.0.0__b03f5f7f11d50a3a/System.Design.dll</p><p>----------------------------------------</p><p>System.EnterpriseServices</p><p>    Assembly Version: 2.0.0.0</p><p>    Win32 Version: 2.0.50727.3053 (netfxsp.050727-3000)</p><p>    CodeBase: file:///C:/WINDOWS/assembly/GAC_32/System.EnterpriseServices/2.0.0.0__b03f5f7f11d50a3a/System.EnterpriseServices.dll</p><p>----------------------------------------</p><p>System.Runtime.Serialization</p><p>    Assembly Version: 3.0.0.0</p><p>    Win32 Version: 3.0.4506.3636 (GDR.030729-3600)</p><p>    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Runtime.Serialization/3.0.0.0__b77a5c561934e089/System.Runtime.Serialization.dll</p><p>----------------------------------------</p><p>System.ServiceModel</p><p>    Assembly Version: 3.0.0.0</p><p>    Win32 Version: 3.0.4506.3636 (GDR.030729-3600)</p><p>    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.ServiceModel/3.0.0.0__b77a5c561934e089/System.ServiceModel.dll</p><p>----------------------------------------</p><p>System.Web</p><p>    Assembly Version: 2.0.0.0</p><p>    Win32 Version: 2.0.50727.3618 (GDR.050727-3600)</p><p>    CodeBase: file:///C:/WINDOWS/assembly/GAC_32/System.Web/2.0.0.0__b03f5f7f11d50a3a/System.Web.dll</p><p>----------------------------------------</p><p>System.Web.Services</p><p>    Assembly Version: 2.0.0.0</p><p>    Win32 Version: 2.0.50727.3053 (netfxsp.050727-3000)</p><p>    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Web.Services/2.0.0.0__b03f5f7f11d50a3a/System.Web.Services.dll</p><p>----------------------------------------</p><p>System.Xml.Linq</p><p>    Assembly Version: 3.5.0.0</p><p>    Win32 Version: 3.5.30729.1 built by: SP</p><p>    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Xml.Linq/3.5.0.0__b77a5c561934e089/System.Xml.Linq.dll</p><p>----------------------------------------</p><p>System.Data.DataSetExtensions</p><p>    Assembly Version: 3.5.0.0</p><p>    Win32 Version: 3.5.30729.1 built by: SP</p><p>    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Data.DataSetExtensions/3.5.0.0__b77a5c561934e089/System.Data.DataSetExtensions.dll</p><p>----------------------------------------</p><p>System.Data</p><p>    Assembly Version: 2.0.0.0</p><p>    Win32 Version: 2.0.50727.3053 (netfxsp.050727-3000)</p><p>    CodeBase: file:///C:/WINDOWS/assembly/GAC_32/System.Data/2.0.0.0__b77a5c561934e089/System.Data.dll</p><p>----------------------------------------</p><p>System.Deployment</p><p>    Assembly Version: 2.0.0.0</p><p>    Win32 Version: 2.0.50727.3053 (netfxsp.050727-3000)</p><p>    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Deployment/2.0.0.0__b03f5f7f11d50a3a/System.Deployment.dll</p><p>----------------------------------------</p><p>System.Xml</p><p>    Assembly Version: 2.0.0.0</p><p>    Win32 Version: 2.0.50727.3082 (QFE.050727-3000)</p><p>    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Xml/2.0.0.0__b77a5c561934e089/System.Xml.dll</p><p>----------------------------------------</p><p>WindowsBase</p><p>    Assembly Version: 3.0.0.0</p><p>    Win32 Version: 3.0.6920.4016 built by: GDR</p><p>    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/WindowsBase/3.0.0.0__31bf3856ad364e35/WindowsBase.dll</p><p>----------------------------------------</p><p>TaskQueue</p><p>    Assembly Version: 1.0.0.0</p><p>    Win32 Version: 1.0.0.0</p><p>    CodeBase: file:///C:/idc/trunk_/TaskQueue/bin/Debug/TaskQueue.EXE</p><p>----------------------------------------</p><p>System.Configuration</p><p>    Assembly Version: 2.0.0.0</p><p>    Win32 Version: 2.0.50727.3053 (netfxsp.050727-3000)</p><p>    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Configuration/2.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll</p><p>----------------------------------------</p><p>gmbg9kuh</p><p>    Assembly Version: 1.0.0.0</p><p>    Win32 Version: 2.0.50727.3624 (GDR.050727-3600)</p><p>    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System/2.0.0.0__b77a5c561934e089/System.dll</p><p>----------------------------------------</p><p><br></p><p>************** JIT Debugging **************</p><p>To enable just-in-time (JIT) debugging, the .config file for this</p><p>application or computer (machine.config) must have the</p><p>jitDebugging value set in the system.windows.forms section.</p><p>The application must also be compiled with debugging</p><p>enabled.</p><p><br></p><p>For example:</p><p><br></p><p><configuration></p><p>    <system.windows.forms jitDebugging="true" /></p><p></configuration></p><p><br></p><p>When JIT debugging is enabled, any unhandled exception</p><p>will be sent to the JIT debugger registered on the computer</p><p>rather than be handled by this dialog box.</p><p><br></p><p><br></p><p> </p>
  • Replied 8 September 2017, 2:45 pm EST

    <p>Hello,</p><p>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. </p><p>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.</p><p>Thanks,</p><p>Manpreet Kaur. <br></p>
  • Replied 8 September 2017, 2:45 pm EST

    <p>Hello, </p><p>  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?</p>
  • Replied 8 September 2017, 2:45 pm EST

    <p>Sample project - farpoint libraries not included</p><p>Farpoint.Win.Spread version 5.0.2003.2008 </p>
    2011/09/WindowsFormsApplication1-2.zip
  • Replied 8 September 2017, 2:45 pm EST

    <p>Hello,</p><p>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.</p><p>I have created a sample depicting the same, please follow the following steps to execute the sample:</p><p>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.</p><p>2. Click on the "Modify datasource" button, this would add some more items to the list.</p><p>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.<br></p><p> Kindly have a look at the sample. Please let me know if you have any queries further.</p><p>Hope it will help you. <br></p><p>Thanks,</p><p>Manpreet Kaur. <br></p>
    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