D
D
DEOVER2019-07-11 14:37:06
Windows Forms
DEOVER, 2019-07-11 14:37:06

C# textbox only output last line?

Friends, all ICE!
Please don't drink too much. A task has been set. In general, there were no problems until I got to getting data on disks, video cards, memory, network cards, etc.
So. The code itself is below. The main problem is that when I receive a response, only the last line is displayed in TEXTBOX. For example: If I have 5 network cards, then only the last one will be displayed, not all. For textbox parameter multiline = true. I'm not a programmer, the task was set, it must be completed, but in what way "The problems of the Negro, the Sheriff ...".
Many thanks in advance!

public string Get_Network_Adapter()

        {
            String result = String.Empty;
            ManagementScope scope = null;

            try
            {
                string NamePC = Convert.ToString(textBoxName.Text);
                ConnectionOptions options = new ConnectionOptions();
                options.Impersonation = System.Management.ImpersonationLevel.Impersonate;

                scope = new ManagementScope("\\\\" + NamePC + "\\root\\cimv2", options);
                scope.Connect();

                ObjectQuery query = new ObjectQuery("Select Caption FROM Win32_NetworkAdapter");
                ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query);

                ManagementObjectCollection queryCollection = searcher.Get();
                foreach (ManagementObject m in queryCollection)
                {
                    result = m["Caption"].ToString();
                }
            }

            catch
            {
                result = "Нет данных";
            }

            return result;
        }

        private void btnGetRequest_Click(object sender, EventArgs e)
        {
            textBoxNetworkAdapter.Text = Get_Network_Adapter();
        }

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question