CellRange Border

Posted by: arungk on 8 September 2017, 1:00 pm EST

  • Posted 8 September 2017, 1:00 pm EST

    <P>Hi,</P>
    <P>I need to apply border for a range of cells selected. I'm doing this in SelectionChanging event as the border should be applied for every move in selection. </P>
    <P>Now my problem is, if I select a different range how do I reset the border for the previous cellrange?</P>
    <P>Arun.G.K</P>
  • Replied 8 September 2017, 1:00 pm EST

    Arun -<br><br>One thing you can try is to use the LeaveCell event and in it call the ResetBorder method on the Cell level.  Or you could set a global flag and set it to false and then in the SelectionChanging event set it to true and query its status and if it's true then call the ResetBorder then set the flag back to false so it won't remove the selection you are beginning.<br>
  • Replied 8 September 2017, 1:00 pm EST

    <FONT size=2>
    <P>Bob,</P>
    <P>Thanks for your help. I need the exact functionality as in the excel sheet. Take a look at my code</P>
    <P></FONT><FONT color=#0000ff size=2>Private</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>Sub</FONT><FONT size=2> FpSpread1_SelectionChanging(</FONT><FONT color=#0000ff size=2>ByVal</FONT><FONT size=2> sender </FONT><FONT color=#0000ff size=2>As</FONT><FONT size=2> System.Object, </FONT><FONT color=#0000ff size=2>ByVal</FONT><FONT size=2> e </FONT><FONT color=#0000ff size=2>As</FONT><FONT size=2> FarPoint.Win.Spread.SelectionChangingEventArgs) </FONT><FONT color=#0000ff size=2>Handles</FONT><FONT size=2> FpSpread1.SelectionChanging</P>
    <P></FONT><FONT color=#0000ff size=2>Dim</FONT><FONT size=2> lineBorder </FONT><FONT color=#0000ff size=2>As</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>New</FONT><FONT size=2> LineBorder(Color.Black, 3)</P>
    <P></FONT>
    <P><FONT color=#008000 size=2></P></FONT><FONT size=2>FpSpread1.ActiveSheet.SetOutlineBorder(e.Range, lineBorder)</P>
    <P></FONT><FONT color=#0000ff size=2>End</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>Sub</FONT></P><FONT color=#0000ff size=2><FONT size=2>
    <P></FONT><FONT color=#0000ff size=2>Private</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>Sub</FONT><FONT size=2> FpSpread1_SelectionChanged(</FONT><FONT color=#0000ff size=2>ByVal</FONT><FONT size=2> sender </FONT><FONT color=#0000ff size=2>As</FONT><FONT size=2> System.Object, </FONT><FONT color=#0000ff size=2>ByVal</FONT><FONT size=2> e </FONT><FONT color=#0000ff size=2>As</FONT><FONT size=2> FarPoint.Win.Spread.SelectionChangedEventArgs) </FONT><FONT color=#0000ff size=2>Handles</FONT><FONT size=2> FpSpread1.SelectionChanged</P>
    <P></FONT><FONT color=#0000ff size=2>Dim</FONT><FONT size=2> lineBorder </FONT><FONT color=#0000ff size=2>As</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>New</FONT><FONT size=2> LineBorder(Color.Black, 3)</P>
    <P>FpSpread1.ActiveSheet.SetOutlineBorder(e.Range, lineBorder)</P>
    <P></FONT><FONT color=#0000ff size=2>End</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>Sub</FONT></P><FONT color=#0000ff size=2><FONT size=2>
    <P>' This will remove border of one cell alone. But I need to reset the border for the whole range, when the range is deselected (which happens when I select someother cell)</P>
    <P></FONT><FONT color=#0000ff size=2>Private</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>Sub</FONT><FONT size=2> FpSpread1_LeaveCell(</FONT><FONT color=#0000ff size=2>ByVal</FONT><FONT size=2> sender </FONT><FONT color=#0000ff size=2>As</FONT><FONT size=2> System.Object, </FONT><FONT color=#0000ff size=2>ByVal</FONT><FONT size=2> e </FONT><FONT color=#0000ff size=2>As</FONT><FONT size=2> FarPoint.Win.Spread.LeaveCellEventArgs) </FONT><FONT color=#0000ff size=2>Handles</FONT><FONT size=2> FpSpread1.LeaveCell</P>
    <P>FpSpread1.ActiveSheet.Cells(e.Row, e.Column).ResetBorder()</P>
    <P></FONT><FONT color=#0000ff size=2>End</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>Sub</FONT></P>
    <P><FONT color=#0000ff size=2>Arun.G.K</P></FONT></FONT></FONT>
  • Replied 8 September 2017, 1:00 pm EST

     Arun -<br><br>I would suggest you change the Cells call to be 0,0,FpSpread1.ActiveSheet.RowCount - 1, FpSpread1.ActiveSheet.ColumnCount - 1.<br><br>This way it will clear any border that is present in the sheet.<br>
Need extra support?

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

Learn More

Forum Channels