This is a migrated thread and some comments may be shown as answers.

RadRichTextBox Dynamic Merge Field Lock

6 Answers 146 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
burk
Top achievements
Rank 1
burk asked on 25 Nov 2014, 08:30 PM
Hi,

I want to lock my merge Fields, but fields get in word docx file and i get with regex in ExpandoObject. How can i lock my fields?

6 Answers, 1 is accepted

Sort by
0
Petya
Telerik team
answered on 26 Nov 2014, 06:09 PM
Hello Baran,

Could you provide more details on the result you are trying to achieve? When you say you need to lock the fields, do you mean you need them to be read-only or something else? I'm also not sure how exactly you use ExpandoObject.

Please get back to us with information on your setup and the desired behavior.

Regards,
Petya
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
burk
Top achievements
Rank 1
answered on 27 Nov 2014, 12:45 PM
Hello Petya,

This is my Xaml.cs Class

public partial class FieldsView : Window
    {
        public FieldsView ()
        {
            InitializeComponent();
        }
        private void RadRibbonButton_Click(object sender, RoutedEventArgs e)
        {
            Expendo = new ExpandoObject();
            IDocumentFormatProvider provider = new DocxFormatProvider();
            OpenFileDialog openDialog = new OpenFileDialog();
            openDialog.Filter = "Documents|*.docx";
            openDialog.Multiselect = false;
            bool? dialogResult = openDialog.ShowDialog();
            if (dialogResult == true)
            {
                using (Stream stream = openDialog.OpenFile())
                {
                    radRichTextBox.Document = provider.Import(stream);
                }
            }
 
              
 
 
 
 
            AddControls();
 
        }
        public dynamic Expendo { get; set; }
        public List<Control> Controls { get; set; }
        private void AddControls()
        {
            Controls = new List<Control>();
            int num= 1;
            IDictionary<string, object> expDict = Expendo;
            //this.radRichTextBox.UpdateAllFields(Telerik.Windows.Documents.Model.FieldDisplayMode.DisplayName);
            var mergeFields = GetMergeFields();
            foreach (string item in mergeFields)
            {
                expDict.Add(item.ToString(), item.ToString());
 
                System.Windows.Controls.Label lbl = new System.Windows.Controls.Label();
                lbl.Content = item;
                TextBox txt = new TextBox();
                txt.Tag = item.ToString();
                txt.Width = 100;
                txt.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
 
                txt.Margin = new Thickness(5, 0, 0, 0);
                 
 
                Controls.Add(lbl);
                Controls.Add(txt);
 
            }
 
            radRichTextBox.Document.MailMergeDataSource.ItemsSource = Enumerable.Repeat(expDict, 1);
 
 
            Button btn = new Button();
            btn.Name = "btn";
            btn.Content = "OluÅŸtur";
            btn.Width = 120;
            btn.Height = 30;
            btn.Margin = new Thickness(0, 20, 0, 0);
            btn.Click += btn_Click;
            Controls.Add(btn);
            Kontroller.ItemsSource = Controls;
        }
 
        private void btn_Click(object sender, RoutedEventArgs e)
        {
            IDictionary<string, object> expDict = Expendo;
            foreach (var control in Controls.ItemsSource)
            {
                if (control is TextBox)
                {
                    TextBox tb = control as TextBox;
                    if (!string.IsNullOrWhiteSpace(tb.Text))
                    {
 
                        //item.ID = tb.Text;
 
                        //foreach (var itemprop in expDict[item.Name])
                        //{
                        //PropertyInfo propertyInfo = item.GetType().GetProperty("ID");
                        //propertyInfo.SetValue(item.ID, tb.Text, null);
 
                        //}
 
 
                        expDict[expDict.Where(x => x.Key == tb.Tag.ToString()).FirstOrDefault().Key] = tb.Text;
                        //this.radRichTextBox.Document.fields
 
                    }
                }
            }
 
 
            //this.radRichTextBox.Document.MailMerge(true);
            //this.radRichTextBox.UpdateAllFields(FieldDisplayMode.Result);
            radRichTextBox.Document.MailMerge();
            radRichTextBox.UpdateAllFields(Telerik.Windows.Documents.Model.FieldDisplayMode.Result);
            radRichTextBox.MailMerge(false);
 
 
        }
 
        private List<string> GetMergeFields()
        {
            XamlFormatProvider provider = new XamlFormatProvider();
            string myXamlString = provider.Export(radRichTextBox.Document);
 
            //doc.MailMergeDataSource.
 
            //doc.MailMergeDataSource.ItemsSource = Enumerable.Repeat(fs.Expando, 1);
 
            MatchCollection matchList = Regex.Matches(myXamlString, "«(.*?)»");
            List<string> list = matchList.Cast<Match>().Select(match => match.Groups[1].Value).ToList();
             
                
             
            return list;
        }
    }

but i dont know how can i lock my merge fields for users touches?










0
Petya
Telerik team
answered on 02 Dec 2014, 11:47 AM
Hello Baran,

I still don't understand what the end goal that you are trying to achieve is. The attached application demonstrates how you can dynamically create and assign to a document a specific data source.

The code you sent us seems to be creating Label and TextBox controls based on the merge fields in a document, but it is not clear to me what the reason for this logic is. Please elaborate on the desired result and on what you mean by "locking" a field.

Regards,
Petya
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
burk
Top achievements
Rank 1
answered on 02 Dec 2014, 12:22 PM
Sorry I could not tell. I have a Word Docx file and it has got some MergeFields. I read them and get in dynamic object, but i want to dont touch any user change Fields in document. I want to change merge fields to read only.
0
Petya
Telerik team
answered on 05 Dec 2014, 09:42 AM
Hello Baran,

There are several ways to make a certain part of your document read-only. For example, you could insert a read-only range around each field in your document. This will prevent users from editing it, but will still allow them to edit other parts of the document.

Alternatively, you can use the Document Protection functionality of the control that allows to set a specific user or a group of users permissions about different regions in the document. 

I hope this is helpful.

Regards,
Petya
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
burk
Top achievements
Rank 1
answered on 23 Jan 2015, 02:30 PM
Hello,

I use dynamic Object in richtextbox like your dynamic sample, but i want to merge table. How can i do this?
Tags
RichTextBox
Asked by
burk
Top achievements
Rank 1
Answers by
Petya
Telerik team
burk
Top achievements
Rank 1
Share this question
or