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.
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
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).
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.
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.
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.
@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 :-)