Fill Multiple Textboxes When Other TextBoxes Fill

Marino Liranzo 81 Reputation points
2024-01-27T16:39:06.09+00:00

I have two groups of text boxes, the first group is populated by implementing the "miDataGrid_SelectionChanged" event with the data of the current row, the second group must be populated by activating an event in the text boxes of the first group, the data for the Second group are the result of another process and are available. The problem is that when the text boxes in the first group are filled, only some of the boxes in the second group are filled.

The following is the code snippet I use for that.

Pn1 = Math.Round(sepEs.X, 3);
Mn1 = Math.Round(sepEs.Y, 3);
Vn1 = Math.Round(lstVn[rowIndex], 3);
ratio1 = Math.Round(Pu / Pn1, 3);
ratio2 = Math.Round(Vu / Vn1, 3);
ratio6 = Math.Round(Mu / Mn1, 3);
ratio3 = lstCtiaV[rowIndex];
ratio4 = lstCtiaH[rowIndex];
ratio4 = lstCtiaC[rowIndex];
ActualizarTextBoxes();
private void ActualizarTextBoxes()
    {
        Task.Factory.StartNew(() =>
                {
                    Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Input, new Action(() =>
                    {
                        txtPn.Text = Pn1.ToString();
                    }));
                    Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Input, new Action(() =>
                    {
                        txtMn.Text = Mn1.ToString();
                    }));
                    Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Input, new Action(() =>
                    {
                        txtVn.Text = Vn1.ToString();
                    }));
                    Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Input, new Action(() =>
                    {
                        Ratio1.Text = ratio1.ToString();
                    }));
                    Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Input, new Action(() =>
                    {
                        Ratio2.Text = ratio2.ToString();
                    })); // does not fill    
                    Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Input, new Action(() =>
                    {
                        Ratio6.Text = ratio6.ToString();
                    }));
                    Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Input, new Action(() =>
                    {
                        Ratio3.Text = ratio3.ToString();
                    })); // does not fill               
                    Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Input, new Action(() =>
                    {
                        Ratio4.Text = ratio4.ToString();
                    })); // does not fill               
                    Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Input, new Action(() =>
                    {
                        Ratio5.Text = ratio5.ToString();
                    })); // does not fill             }); 		}
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
11,275 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Mohammed Hantour 0 Reputation points
    2024-01-27T18:10:03.23+00:00

    It looks like you are not defining "ratio5" in your code.


  2. Jiale Xue - MSFT 48,861 Reputation points Microsoft Vendor
    2024-01-29T06:51:27.47+00:00

    Hi @Marino Liranzo , Welcome to Microsoft Q&A,

    First modify this code,

    ratio4 = lstCtiaH[rowIndex]; 
    ratio5 = lstCtiaC[rowIndex]; // Assigning lstCtiaC to ratio5
    

    Make sure that lstCtiaH, lstCtiaC, and lstCtiaV contain the expected values. If the issue persists, you may want to debug the code by checking the values of lstCtiaH, lstCtiaC, and lstCtiaV at runtime to identify any potential issues with the data sources.

    Make sure that the data sources required for the second set of text boxes (lstCtiaH, lstCtiaC, and lstCtiaV) actually contain the expected values. You can check this by printing or debugging the values at the appropriate location.

    Make sure you use the correct index when populating the second set of text boxes. If the index exceeds the range of the array or collection, unexpected results may occur.

    Make sure the second set of text boxes are visible when filled. If the text box is hidden or disabled, the populated value may not be displayed.

    Best Regards,

    Jiale


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". 

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.