|
Dear Expert,
I had successfull develop class for data collection however its display in command prompt, however how do i display this info in form textbox1, following is my class code
------------------------------------------------------------------------------------
using System;
using System.Management;
namespace remoteconnect
{
class Program
{
static void Main(string[] args)
{
ManagementScope scope =
new ManagementScope(
"\\\\computername\\root\\cimv2");
scope.Connect();
ObjectQuery query = new ObjectQuery(
"SELECT * FROM win32_computersystem");
ManagementObjectSearcher searcher =
new ManagementObjectSearcher(scope, query);
ManagementObjectCollection queryCollection = searcher.Get();
foreach (ManagementObject m in queryCollection)
{
if (m.Properties["IsValid"].Value != null && m.Properties["IsValid"].Value.ToString() == "True")
m.Properties[""].Value.ToString();
}
}
}
}
----------------------------------------------------------------------------------------------------
In Form yet nothing but created texbox and button
----------------------------------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace remoteconnect
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
}
}
}
----------------------------------------------------------------------------------------------------------
would you please assist in regards....
|
|
|
|
|
You could use a ListBox [^] or similar control.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
in this case what will be the cript
to trigger the data in listbox
|
|
|
|
|
That is something you need to decide based on your program requirements. You could do it when the program starts and the form first loads, or you could do it in response to some external event such as a button press.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
Did you want a click on the Button to trigger the reading of the Properties collection, and the writing of some data in each Property to the TextBox ? That's a guess
Let's say you name your Button "WriteQueryCollectionBtn," and your TextBox "PropertyTextBx" ...
In that case, perhaps your Button's Click EventHandler might look like:
private void WriteQueryCollectionBtn_Click(object sender, EventArgs e)
{
foreach (ManagementObject m in queryCollection)
{
if (m.Properties["IsValid"].Value != null
&& m.Properties["IsValid"].Value.ToString() == "True")
{
PropertyTextBx.Text += m.Properties[""].Value.ToString() + Environment.NewLine;
}
}
} Note that for this code to work in the Form, you would have to also reference the System.Management library with a 'using statement.
It's not clear here if you are going to "connect" and retrieve the data once, when the application starts (as you are doing now), or:
If you are going to want to pull-down the data every time the Button is clicked: my guess is that you'd want to refresh the data each time the Button is clicked, which will require you re-architect your code shown here.
The question here is: does the data change, or is it always the same ?
Again, this reply is pretty much a "blind guess" at what you might want to do. You'll have to be much more specific about your goals here, and the nature of the data, if you want more specific feedback.
good luck, Bill
|
|
|
|