Content Controls Bombobox change colour with selection

1 Answer 46 Views
WordsProcessing
Roger
Top achievements
Rank 2
Roger asked on 16 Jul 2023, 09:46 PM

We have a scenario where the client is wanting a combobox in a generated Word document to have the color of the combobox change depending on the option selected (these combo boxes are repeated many times in the document so the colour change is important to the client.

Screenshot shows  the Combobox in use. Below is the snippet of my code. Is there a way to do what I am after?

RadFlowDocumentEditor editor = new RadFlowDocumentEditor(document);
// In my source (an html document that was converted to a Word Document higher in the code) "#ddlApplies" is where I need to place a ComboBox
// It is in a table cell.
ReadOnlyCollection<FindResult> findResults = editor.FindAll("#ddlApplies", matchCase: false, matchWholeWord: false);
foreach (var item in findResults)
{
	string foundVal = item.Runs[0].Text.Replace("#", "");
	// The full run name consists of "#ddl|Identifier". In Furture dev we will use the Identifier (which is put in as the alias) to identify which control this is so we can read in the document and update other datasets
	//var ddlContentControl = editor.InsertStructuredDocumentTag(SdtType.ComboBox);
	ComboBoxProperties properties = new ComboBoxProperties();
	// Complies --- Green
	// Does not Comply --- Red
	// Minor Variation --- Orange
	// N/A -- Grey
	properties.Items.Add(new ListItem() { DisplayText = "Complies", Value = "Complies" });
	properties.Items.Add(new ListItem() { DisplayText = "Does not Comply", Value = "Does not Comply" });
	properties.Items.Add(new ListItem() { DisplayText = "Minor Variation", Value = "Minor Variation" });
	properties.Items.Add(new ListItem() { DisplayText = "N/A", Value = "N/A" });
	// Setting the alias with the identifier.
	properties.Alias = foundVal.Split("|")[1];
	properties.Lock = Lock.SdtLocked;
	properties.Placeholder = new Placeholder() {
		PlaceholderText = "Select",
		ShowPlaceholder = true
	};
	properties.OutlineAppearance = OutlineAppearance.BoundingBoxes;
	//setting the properties
	properties.RunProperties.CopyPropertiesFrom(item.Runs[0].Properties);
	/***
	Here is where I think I need to set things. But not sure how. Client wants each option to have a different colour. They would prefer the whole cell to change, but happy if I can just get the ComboBox to change.
	
	***/
	
	//inserting the Tag and setting the default value
	editor.MoveToInlineStart(item.Runs[0]);	
	editor.InsertStructuredDocumentTag(properties, item.Runs[0], item.Runs[0]);
	item.Runs[0].Text = "Select";	

}

1 Answer, 1 is accepted

Sort by
0
Accepted
Vladislav
Telerik team
answered on 17 Jul 2023, 09:52 AM

Hi Roger,

The possible values for the combo box are saved inside the document as plain text only (this is by specification). The whole combo box might have a custom style but it is for the entire item. For the expected behavior to work, you must handle it inside the editor (provided that this editor has an event that you might use) that the end user will use.

If you are willing to use a spreadsheet (Excel) document instead, you can achieve this by utilizing Data Validation for preparing the combo box values and Conditional Formatting for styling the values. The Conditional Formatting feature helps you define how certain items should be visualized based on their current value.

I hope you will find this information helpful. Do not hesitate to contact us, should you have any other inquiries.

Regards,
Vladislav
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Roger
Top achievements
Rank 2
commented on 18 Jul 2023, 04:56 AM

Hi Vladislav,

The editor for the end user is MSWord, so that is unfortunately not something we can add event handlers to (we do have an alternative solution that is a Word plug-in, but getting approval for that to be deploying simply isn't going to happen)

And while a spreasheet would make life easier, again, the client wants it in MSWord.

Thanks
-Roger
Vladislav
Telerik team
commented on 18 Jul 2023, 05:41 AM | edited

Hi Roger,

I am sorry to hear that. As previously said, the described behavior can only be implemented on the editor that the end user is interacting with. The Office Open XML format does not contain any construct that might help you achieve this. Even if we make a custom implementation in our libraries and find some way to export as metadata inside the DOCX format, the editor opening the document will not know how to interpret this information because it is not part of the specification. So, your best bet is to try and convince your client to use the plug-in that you have in mind if they want to use this functionality.

I am sorry I was not able to provide you with any pleasable solution but this is not something that we have control over. I hope you understand.

Tags
WordsProcessing
Asked by
Roger
Top achievements
Rank 2
Answers by
Vladislav
Telerik team
Share this question
or