|
In your variable declarations, change "ManagementQuery" to "ObjectQuery". You cannot declare an instance variable as an abstract class type and then start calling methods and setting properties on it as the abstract class won't have implementations of those properties and methods.
ManagementObjectSearcher objSearcher = null;
ManagementObjectCollection objCollection = null;
ManagementScope objScope = null;
ObjectQuery objQuery = null;
ConnectionOptions objOptions = null;
modified 9-Oct-19 15:10pm.
|
|
|
|
|
Thank you to all and to Dave thank you for correcting me.
Now i'm very happy to have completed this code.
I thank all of you again for helping.
Wish you a lovely day
|
|
|
|
|
|
I spun a quick project and copy'n'pasted the OP's code into it. Sure enough, he's got the exact error message and the line in comes up on correct.
It took me an embarrassing number of minutes staring at it before I looked up the ManagementObject class and saw it was an abstract. Then it all clicked.
|
|
|
|
|
Hi Dave and Richard, thank you for checking my code.
Richard yes that is error I’m getting and thank you trying Dave.
I’m stuck and will have to check Microsoft links tomorrow at work like I said it is my first time and I’m stuck and don’t understand.
Dave since you tried and saw the errors would you be kind to highlight where I’m going wrong so that I can learn from please but if you think it’s better to read the links then I would do that but if I’m not mistaken I got some of the code from Microsoft to understand and I tried but without success.
Thank you and have a great evening.
|
|
|
|
|
He told you exactly what to do in his original reply!
Did you try it at all?
Sent from my Amstrad PC 1640
Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Thank you Griff, Sorry as I’m new to this forum I apologize I didn’t see the first reply he did and I will try it tomorrow morning 🙏.
Thank you and wish you a lovely evening.
|
|
|
|
|
Hi All,
Is there a simple C# Dot Net API available to record AVI files for a given set of BMP images ?
Would appreciate any code samples that shows the usage of such an API !
Thanks In Advance !
|
|
|
|
|
Check the .NET documentation, and also Google.
|
|
|
|
|
|
What do you mean by "column header sort doesn't work"?
Please show your sort method, and explain which part of it has the problem.
|
|
|
|
|
I want to number the dataGgridView but it doesn't work, you see the red rectangular image file
|
|
|
|
|
The image you have posted is not viewable and cannot be downloaded without creating a Mediafire account. Please post the actual code in your original question and explain what the error is and where it occurs.
|
|
|
|
|
I will post code does not work, I will post my code for you to see, what am I wrong with ?
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.dataGridView1.VirtualMode = false;
this.dataGridView1.SortCompare += new System.Windows.Forms.DataGridViewSortCompareEventHandler(this.dataGridView1_SortCompare);
dataGridView1.DataSource = CreateTable(5);
}
private static DataTable CreateTable(int RowCount)
{
DataTable tbl = new DataTable();
tbl.Columns.Add("check1", typeof(bool));
tbl.Columns.Add("ID", typeof(int));
tbl.Columns.Add("Name", typeof(string));
tbl.Columns.Add("Number", typeof(int));
tbl.Columns.Add("Date", typeof(DateTime));
tbl.Columns.Add("check2", typeof(bool));
for (int i = 0; i < RowCount; i++)
tbl.Rows.Add(new object[] { false, i, String.Format("Name{0}", i), 3 - i, DateTime.Now.AddDays(i), true });
return tbl;
}
private void dataGridView1_SortCompare(object sender, DataGridViewSortCompareEventArgs e)
{
e.SortResult = System.String.Compare(
e.CellValue1.ToString(), e.CellValue2.ToString());
if (e.SortResult == 0 && e.Column.Name != "ID")
{
e.SortResult = System.String.Compare(
dataGridView1.Rows[e.RowIndex1].Cells["ID"].Value.ToString(),
dataGridView1.Rows[e.RowIndex2].Cells["ID"].Value.ToString());
}
e.Handled = true;
}
}
image file http://www.mediafire.com/view/9ogb4uwvfr2ag3i/dgv2.jpg/file
|
|
|
|
|
|
all the code I copied from microsoft company, even the top of the page I posted without you reading my first questions, now you give the same link from microsoft company. Before you criticize others, have you tried my example ?
|
|
|
|
|
I posted that link to emphasise the point that you were using the Microsoft code. However, you have still, despite three requests, not explained what your problem is.
[edit]
And to answer your question, yes I have tried the example, and it works fine.
[/edit]
|
|
|
|
|
I found out why the dataGridView1_SortCompare method doesn't allow dataGridView1.DataSource to be assigned if using the sort feature.
|
|
|
|
|
Using the DataContract serialize/deserialize facilities in System.Runtime.Serialization is very convenient, reliable. It does produce verbose xml with rather stunningly long labels like:
</KeyValueOfPersonLikeIntensityvlZcIX2K></Value></KeyValueOfPersonArrayOfKeyValueOfPersonLikeIntensityvlZcIX2Kg_S_SinKSu></ArrayOfKeyValueOfPersonArrayOfKeyValueOfPersonLikeIntensityvlZcIX2Kg_S_SinKSu> That's serialized output from a graph engine I am writing. However, by using GZip you can compress that by factors of #20, or more.
It is interesting to observe that if a Class inherits from a generic structure, like:
[DataContract]
public Class Graph<TVertex, TEdge> : Dictionary<TVertex, Dictionary<TVertex, TEdge>> That will fail to serialize; however, by removing the 'DataContract Attribute, and adding the 'Serializable Attribute, it will serialize properly using a 'DataContractSerializer. This works:
[Serializable]
public Class Graph<TVertex, TEdge> : Dictionary<TVertex, Dictionary<TVertex, TEdge>> And, you can, of course still have the Class as generic, and make an internal field/property of the necessary Type marked with the 'DataMember Attribute:
[DataContract]
public Class Graph<TVertex, TEdge>
{
[DataMember]
public Dictionary<TVertex, Dictionary<TVertex, TEdge>> GraphDict { set; get; }
} I haven't seen any documentation on this, but the error message is what suggested trying to replace 'DataContract with 'Serializable:
System.Runtime.Serialization.InvalidDataContractException
HResult=0x80131500
Message=Type 'Graph_2019_2.PersonLikeGraph' cannot be ISerializable and have DataContractAttribute attribute. So, you be the judge: hack, or useful information ? Anomalous but reliable, or, anomalous and unreliable ?
Note: while the observations I cite are all based on FW 4.8: the behavior described has been encountered with many previous FW versions.
«One day it will have to be officially admitted that what we have christened reality is an even greater illusion than the world of dreams.» Salvador Dali
modified 8-Oct-19 14:17pm.
|
|
|
|
|
BillWoodruff wrote: So, you be the judge: hack, or useful information ? Anomalous but reliable, or, anomalous and unreliable ? Since it is not documented, I'd say such behaviour might change between releases. For MS, anything undocumented is unsupported and "subject to change".
I wouldn't rely on it for anything in production. Does your engine require it, or can you live without?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
|
I made a "mental bet" with myself that Richard Deeming would respond to this with something relevant
As I read the article you cited, it appears to be talking about inheriting from Interfaces, not generic Type declarations. I don't see those two issues as the same, but, of course, may be wrong.
What interests me is that the Class marked as [Serializable] has its properties adorned with either [DataMember], or, [IgnoreDatamember]: and, the DCS used to serialize is doing the "right thing."
Seems to me the compiler should "see" the Class is marked with [DataMember], and inherits from a generic type declaration ... and throw a build error.
thanks, Bill
«One day it will have to be officially admitted that what we have christened reality is an even greater illusion than the world of dreams.» Salvador Dali
|
|
|
|
|
Dear CodeProject members,
Hope you can help with C# that i have been doing since last week.
I'm new C# and compiled this but only getting IPv6
private void Ping_Click(object sender, EventArgs e)
Ping ping = new Ping();
PingReply Reply = ping.send(Hostname,1000);
LW ("IP Address [ + Reply.Address +"]");
LW ("IP Address [ + Reply.Status +"]");
private void LW (string Line = "")
this.Log.Text += Line;
Thank you and much appreciate your help.
|
|
|
|
|
|
If you pass in a host name, the Send method calls Dns.GetHostAddresses[^] and pings the first address returned.
If you want to force it to ping the IPv4 address - assuming there is one - then you'll need to call Dns.GetHostAddresses yourself. You can then find the address you want to ping, and pass that into the Send method instead of the host name.
Eg:
IPAddress address = Dns.GetHostAddresses(Hostname)
.OrderBy(a => a.AddressFamily == AddressFamily.InterNetwork ? 0 : 1)
.FirstOrDefault();
if (address == null) throw new InvalidOperationException($"Cannot resolve host '{Hostname}'.");
PingReply reply = ping.Send(address, 1000);
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|