Welcome to the SRP Forum! Please refer to the SRP Forum FAQ post if you have any questions regarding how the forum works.

Clear method doesn't clear formatting

Hi,

I have created an edit table, where I present grouped data by adding a subheader. This subheader is simply a row with merged cells, a background color, and bold text. It looks pretty cool.

Now, when I change my filters and press "reload", I renew the data by setting the list directly to the control. So this overwrites all the data. This doesn't clear the formatting though, which could make sense I suppose. So I thought I'd use the "Clear" method.

This doesn't really work as expected though, because the first row of my table isn't removed, which of course is the 'subheader' with merged cells. If I now add data to my table, the styles from this config are used for all the new cells as well, so all my records now have a merged cell with a green background.

I did find a work around: I now add an empty row on the first line, which I set to invisible after all the data has been loaded. When I load new data, I first send_message "Clear", then make the first line visible again, then load the data, and then make the first line invisible again. Before this, I set Redraw to 0, so it looks okay.

So I was wondering if there is a better way of doing this. And also I thought maybe this post would help somebody else with the same issues.


Comments

  • Near as I can tell, your experience is not unexpected. The Clear method clearly states that it "removes all data leaving blank records". Formatting, especially custom formatting, is left alone.

    While I am thinking of possible better ways to handle this, how do you handle your subsequent subheaders? Aren't you always adding those after the fact? Just curious as to why they aren't a part of the same problem (and solution).
  • Well, if you use Clear with option 0, it leaves just one blank record. I can't think of a use case when you want to clear all your data, but keep properties like MergeCells and FontColor for the first (now empty) row, which will then be applied to *all* the new rows you insert after the clear operation.

    In my case, I sort my array by date, and then group the data by month, so the header will be displaying the month. I did this by looping through my data array, detecting when the month changes. Then I insert the header with Insert() and store the position in an array (e.g. HeadersToFormat<-1> = i). Then when I'm done with the data array, I'll loop through my HeadersToFormat, and apply the MergeCells property to these rows (and also CellProtection, CellFont and CellColors).

    So I could just set these properties for *every* row, setting them to default when it's not a header, but just clearing and starting with a clean slate would be better, because you don't have to remember the default states then.
  • Formatting cells takes a bit of effort on the part of the programmer, so new rows always inherit the formatting of the row immediately above them as a matter of convenience. Imagine, instead of a first-row header, you simply had a uniform table, but each column were uniquely formatted. In that scenario, the fact that the Clear method preserves formatting for that first row is convenient.

    In short, this is all by design. I have used the SRP EditTable to make hierarchical tables before, and there is no way around the extra effort. I think your approach is clever and efficient, though I don't think you need to make the invisible row temporarily visible. Good on you for setting Redraw to 0 during the process. That is often overlooked.
  • I too have tried this sort of thing before and for similar reasons. I play. I experiment. I get excited. I get frustrated. I get excited again.
    In the end I almost always come to the realisation that I was really looking for a reporttable and in half an hour to an hour I effectively have what I just spent three days experimenting with an edittable to try and achieve.
  • @Kevin: Okay, I see your point, and I do understand the use case now. If I don't make the first row visible before injecting my new data, the invisible property is also inherited, so all my new rows will be invisible.

    @AusMarkB: That's what my collegae suggested as well when I showed my formatted edittable :-). I think I will try this solution a little longer, because I also want to sum columns and show a total. But you're probably right, I am probably over-complicating things :-)
  • By all means, play on. I always do but for what it's worth the reporttable will sum and total for you including sub totals where you group
Sign In or Register to comment.