RadRichTextBox Dynamic Merge Field Lock

7 posts, 0 answers
  1. burk
    burk avatar
    9 posts
    Member since:
    Feb 2014

    Posted 25 Nov 2014 Link to this post

    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?
  2. Petya
    Admin
    Petya avatar
    975 posts

    Posted 26 Nov 2014 Link to this post

    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.

     
  3. UI for WPF is Visual Studio 2017 Ready
  4. burk
    burk avatar
    9 posts
    Member since:
    Feb 2014

    Posted 27 Nov 2014 in reply to Petya Link to this post

    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?










  5. Petya
    Admin
    Petya avatar
    975 posts

    Posted 02 Dec 2014 Link to this post

    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.

     
  6. burk
    burk avatar
    9 posts
    Member since:
    Feb 2014

    Posted 02 Dec 2014 in reply to Petya Link to this post

    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.
  7. Petya
    Admin
    Petya avatar
    975 posts

    Posted 05 Dec 2014 Link to this post

    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.

     
  8. burk
    burk avatar
    9 posts
    Member since:
    Feb 2014

    Posted 23 Jan 2015 in reply to Petya Link to this post

    Hello,

    I use dynamic Object in richtextbox like your dynamic sample, but i want to merge table. How can i do this?
Back to Top
UI for WPF is Visual Studio 2017 Ready