Question

Im creating a new cell = new XRTableCell();

I'll show a sample of my code. I always ending up with the same color in my cell, even if I change it in my "If".

foreach (TaskTime tt in di.TaskTimes[i])
                    {
.....

TimeToAdd = ClassLibrary.Utils.GetTimeStringFromSec(tt.FromSec % 86400) + " - " + ClassLibrary.Utils.GetTimeStringFromSec(tt.UntilSec % 86400) + " (" + tt.Abbreviation+ ")";

                        if (taskTimeTextBox.Text.Length > 0)
                            taskTimeTextBox.Text += "\n";
                        taskTimeTextBox.Text += TimeToAdd;

if (tt.OnOtherCostDivision)
                            {
                                taskTimeTextBox.SelectionStart = taskTimeTextBox.Find(TimeToAdd);
                                taskTimeTextBox.SelectionFont = new Font("Calibri", 9, FontStyle.Italic);
                                taskTimeTextBox.SelectionColor = Color.Gray;
                            }
                            else
                            {
                                taskTimeTextBox.SelectionStart = taskTimeTextBox.Find(TimeToAdd);
                                taskTimeTextBox.SelectionFont = new Font("Calibri", 9, FontStyle.Italic);
                                taskTimeTextBox.SelectionColor = Color.Blue;
                            }

                richTxtObject.Rtf = taskTimeTextBox.Rtf;
                cell.Controls.Add(richTxtObject);
            }
            row.Cells.Add(cell);
Was it helpful?

Solution

Soulved it! Didn't worked when I had it this way "taskTimeTextBox.Text += xxxxxxxx ". So I made a list of string, saved my text in if it were "onOtherCostDivision". Later on I hade to loop true my list and see if the final taskTimeTextBox.Text had the text in it and in that cause I added the color.

                    foreach (var task in taskCostDivList)
                {
                    if (taskTimeTextBox.Text.Contains(task))
                    {
                        taskTimeTextBox.SelectionStart = taskTimeTextBox.Find(task);
                        taskTimeTextBox.Font = new Font("Calibri", 9, FontStyle.Italic);
                        taskTimeTextBox.SelectionColor = Color.Gray;
                    }
                    else
                    {
                        taskTimeTextBox.Font = new Font("Calibri", 9, FontStyle.Regular);
                        taskTimeTextBox.SelectionColor = Color.Black;
                    }
                }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top