0

I need help creating a CtrlAddIn for Dynamics NAV using C#

I am quite new to matrix and c#, i am using WinForm and VisualStudio to create a DLL.

Here is part of the code:

region Fonctions pilotées depuis Dynamics

    // Tout effacer

    [ApplicationVisible]
    public void CleanPanel()
    {
        MainPanel.Controls.Clear(); //Tous les elements seront effacés
    }

    // Gestion des rôles

    [ApplicationVisible]
    public void AjouterRole(string NameL, string idRoleL, int posRoleL)
    {            
        TextBox tb = new TextBox();
        //Random random = new Random();
        ToolTip TTL = new ToolTip();
        String TooltipL;

        //int randRed = random.Next(1, 255);
        //int randGreen = random.Next(1, 255);
        //int randBlue = random.Next(1, 255);

        //tb.BackColor = Color.FromArgb(randRed, randGreen, randBlue);
        tb.BackColor = Color.Bisque;
        tb.Name = idRoleL;
        //si le texte est plus grand, je mets ...
        tb.Text = NameL;
        if (tb.TextLength > 7)
        {
            string nameO = NameL.Substring(0, 7);
            string points = "...";
            tb.Text = string.Concat(nameO + points);
        }
        else
        {
            tb.Text = NameL;
        }
        tb.AllowDrop = true; //pour le drag and drop                      
        tb.Multiline = true;//pour pouvoir avoir des textboxes de taille differente
        tb.ScrollBars = ScrollBars.None; //pour enlever les scrollbars dans tout les textboxes
        tb.HideSelection = true;//pour ne pas avoir le focus dans le precedent textbox
        tb.Size = new Size(70, 60);
        tb.Left = posRoleL * 70;
        tb.Visible = true;
        tb.Cursor = Cursors.Hand;
        //wrap pour que le texte n'aille pas a la ligne et tooltip pour voir le text
        TooltipL = NameL;
        tb.WordWrap = false;
        TTL.SetToolTip(tb, TooltipL);
        //evenement pour le DRAG AND DROP
        //1 Je gere le drag pour pouvoir le bouger
        tb.MouseDown += (senderL, eL) => tb.DoDragDrop(tb.Text, DragDropEffects.Move);
        tb.DragEnter += (senderL, eL) => { eL.Effect = DragDropEffects.Move; };
        //EventControlAddin(3, idRoleL.PadRight(10) + ";" + (string)posRoleL.ToString());
        //2 Je gere le drop pour pouvoir bouger le controle
        tb.DragDrop += (senderL, eL) => { tb.Text = eL.Data.GetData(DataFormats.Text).ToString(); EventControlAddin(3, idRoleL.PadRight(10) + ";" + (string)posRoleL.ToString()); };
        //evenement pour pouvoir supprimer un role
        tb.MouseEnter += IlumineRole;
        tb.MouseLeave += Eteint;
        //evenement pour modifier le role
        tb.DoubleClick += (senderL, eL) => EventControlAddin(6, tb.Name);

        MainPanel.Controls.Add(tb);

    }

    [ApplicationVisible]
    public void AjouterTotalRole(string NameL, string idRoleL, int posRoleL, string dureeL, string coutL)
    {            
        // Textbox
        TextBox tb = new TextBox();
        tb.Name = idRoleL;
        tb.Text = NameL;
        int indexMaxRoles = 99;//somme de toutes les lignes + 1 
        // Je dois mettre un tooltip pour comprendre
        ToolTip TTL = new ToolTip();
        String TooltipLCout = "Totaux des rôles en durée et en coût.";
        //Panel contenant les labels
        Panel pn = new Panel();
        pn.Size = new Size(70, 60);
        pn.BackColor = Color.Azure;
        pn.BorderStyle = BorderStyle.FixedSingle;
        pn.Left = posRoleL * 70;
        pn.Top = indexMaxRoles + 1; //Il faut qu'il soit a la casse finale

        Label lb_Duree = new Label();          
        lb_Duree.Text = "Durée:" + dureeL;
        //lb_Duree.Width = 60;
        Label lb_Cout = new Label();
        lb_Cout.Text = "Coût:" + coutL;
        //lb_Cout.Width = 60;
        lb_Cout.Top = 20;

        TTL.SetToolTip(pn, TooltipLCout);
        pn.Controls.Add(lb_Duree);
        pn.Controls.Add(lb_Cout);
        MainPanel.Controls.Add(pn);
    }

I need to add the total of the rows and columns as TotalRoles and TotalOperations, and i need to pass to dynamics the lastposition of my textboxes in horizontal and vertical, + 1 for getting the right position. How can i do this? Any help most welcome. Thanks

Nirtun
  • 47
  • 10
  • Is this for a Silverlight control? We need more details about where exactly the code is going to execute. – Nicknow Feb 28 '14 at 21:45
  • Hi Nicknow, the code is going to execute as a CtrlAddIn for NAV 2013 CRM. – Nirtun Mar 03 '14 at 07:55
  • Okay, so what part of your question is specific to Dynamics CRM? Also, you should add the Dynamics NAV (I'll do an edit for you) to get the right audience. – Nicknow Mar 03 '14 at 22:42
  • C'est quoi ce commentaire en espagnol quand les autres sont en français ? (et au mieux, pour ici, les mettre en anglais). – Xaruth Mar 03 '14 at 23:09
  • traduce : WTF is that spanish comment when all others are in french ? Better to do all in english when posting on Stackoverflow. – Xaruth Mar 03 '14 at 23:10
  • First comment: "changing the properties to do the table as i want" – Nirtun Mar 04 '14 at 07:54
  • Second comment: "I have to delete the space left after dimensioning the cells"... – Nirtun Mar 04 '14 at 07:55

1 Answers1

0

The control add-in should render the same as a Custom Control in Visual Studio, however there may be some default margins applied. Check that your margin property is set on your textboxes to explicitly set it to zero.

Also, put your controls inside a better container such as a Panel, TableLayoutPanel or FlowLayoutPanel. These more specialized controls should make it easier to arrange the child elements without having to manually calculate positions, etc.

Matrix Forms in RTC

Dynamics NAV already has the ability to display matrix-style forms -- is there a particular use-case where a custom matrix add-in would be more applicable? Distributing a client-side control add-in DLL to all users can be difficult to debug and maintain.

There are walkthroughs on MSDN which explain the process of migrating the classic Matrix forms to the RTC client if that is your underlying objective.

Jake Edwards
  • 1,190
  • 11
  • 24
  • Developing RoleTailored Client Control Add-ins, this is what i am doing. I explain: I have a main panel, Inside it i want to add some other panels that will contain arrays of textboxes, one of them will be bidimensional and the rest unidimensionals arrays. But my problem is that i can't see the elements Inside the panels. I can see all the panels but no the elements. – Nirtun Mar 12 '14 at 16:28
  • Without any sample code, it's difficult to say. I'd make sure you're adding your panels to the parent control. Try adding something basic like a label to ensure they're displaying at all. More documentation can be found on MSDN -- http://msdn.microsoft.com/en-us/library/dd983826(v=nav.70).aspx – Jake Edwards Mar 13 '14 at 07:25
  • i have just refresh my code for you too see, thanks for any help – Nirtun Mar 18 '14 at 13:48