|
The thing is, you have to use different languages within different contexts.
You probably won't ever do device driver dev. in C# or client-side scripting in C++.
Cheers,
Simon
"The day I swan around in expensive suits is the day I hope someone puts a bullet in my head.", Chris Carter.
animation mechanics in SVG
|
|
|
|
|
I've seen this in the Managed DirectX samples:
MouseState mouseStateData = new MouseState();
// Get the current state of the mouse device.
mouseStateData = applicationDevice.CurrentMouseState;
Could you explain me why there is a need to instanciate the MouseState class? Doesn't the property return an object? Isn't the expression "new MouseState()" redundant?
|
|
|
|
|
You are most likely correct, and I have seen many such examples in various .Net docs. I have always been able to remove the unnecessary instantiation, as one would expect. Do not assume example code writers have their code carefully checked. They don't have to produce good code, and rarely do they ever receive feedback.
Cheers
|
|
|
|
|
I used the DataTable.Rows.Find() to get a DataRow. Now how do I obtain that row's table index?
I dont see any DataRow.Index property or DataTable.Rows.IndexOf(PrimaryKey) method.
|
|
|
|
|
Hey every one, does any one know what the hell is wrong with this code =/
i am trying add a Node(file to the treeNode)works fine except
that
i am doing a check to see that the user wont add a same file 2wice but its
not returning a right value
its the second if statment
can you tell me whats wrong with my code thx
//Add Nodes to Tree
<br />
private void Add_Click(object sender, System.EventArgs e) {<br />
<br />
TreeNode currentNode;<br />
<br />
<br />
OpenFileDialog ofd = new OpenFileDialog();<br />
<br />
ofd.Filter="lib files (*.dll)|*.dll|Executable files(*.exe)|*.exe";<br />
<br />
<br />
if(ofd.ShowDialog()==DialogResult.OK){<br />
<br />
currentNode = new TreeNode(Path.GetFullPath(ofd.FileName));<br />
<br />
<br />
if(treeView1.Nodes.Contains(currentNode)==false){<br />
<br />
treeView1.Nodes.Add(currentNode);<br />
<br />
numberFiles = treeView1.Nodes.Count;<br />
<br />
Counter.Text=numberFiles.ToString();<br />
<br />
}<br />
<br />
else{<br />
<br />
MessageBox.Show("File AlreadyBeen selected","Warnning");<br />
<br />
currentNode=null;<br />
<br />
}<br />
<br />
}<br />
<br />
}<br />
Thanks in Advance
Amir
|
|
|
|
|
Amir G wrote:
currentNode = new TreeNode(Path.GetFullPath(ofd.FileName));
if(treeView1.Nodes.Contains(currentNode)==false){
You are comparing 2 instances of TreeNode objects, which will allways return not equal, unless you comparing it from a reference (but thats not what you should be doing). The TreeNode object has exactly what you are looking for in the Tag property. Here you can add some string or number and use that to check for equality, not the actual TreeNode objects.
Who is this miscrosoft, and what devilish plans have they for us?
|
|
|
|
|
leppie wrote:
Here you can add some string or number and use that to check for equality, not the actual TreeNode objects
could you please explain a bit more i dont follow you
thx
|
|
|
|
|
currentNode = new TreeNode(Path.GetFullPath(ofd.FileName));
currentNode.Tag = Path.GetFullPath(ofd.FileName);
if(CheckNode(currentNode)){
Then
private bool CheckNode(TreeNode node)
{
string test = (string) node.Tag;
foreach (TreeNode n in treeView1.Nodes)
if (n.Tag == node.Tag)
return false;
return true;
}
Who is this miscrosoft, and what devilish plans have they for us?
|
|
|
|
|
Your code is written well, but Contains() does not do what one might expect it to.
I have had exactly the same problem, and lost a lot of hair researching this. The CLR TreeView has no way of finding a node by name, even though the Contains() method looks like it would provide that functionality. Contains() returns true only if the node passed to it, is the exact same node as one already in the TreeNodeCollection. I do not see a lot of use for such functionality, but that is the way it is.
What we are interested in is a way to see if there is already a node with a specific name (or full path). There are a number of ways of testing this, and most rely on enumerating some nodes, and seeing if one of the names matches the one being sought. Incidentally, a TreeNodeCollection can contain multiple nodes with exactly the same name, which might be one reason searching for a "unique name" was not implemented.
In your case, it looks as though each node's name contains full path info, so this might not be too difficult. In my case, I had nodes branched-out into dir trees, which required parsing each path into separate dir names, and walking the tree.
Anyway, I enumerated by grabbing the node returned by FirstNode, which gets a node's first child node. With the node returned (if not null), I kept calling NextNode to get the rest of the child nodes. I did this until null was returned (no more child nodes). If there is a match, continue deeper if necessary, using the same methods (I used recursive calls).
In my case I wrote a search function that took an array of node names, which were parsed from the path to look for. I hope some of this helps.
Cheers
|
|
|
|
|
Thank you Both Jeff J for that great comment and help and Leppie for explanation and the code
I appreciate it
Amir
|
|
|
|
|
i use sharp develop most the time these days...(cant afford vs yet ) anyways i try get say a icon that i want embedded in my dll to embedd but it doesnt seem too do it. (im a total newb when it comes to embedding anyway)can someone help me by supply code too get me on my feet? i have never used reflection but i want too use it so i can put all my icons in one neat little dll. please supply code for embedding and then calling a iconfile (and say setting it too...this.Icon or something) if you have the time it would really really really help me out.. thanks alot.
Icon File Name : Icon_Question.ico
P.s: i tryed reading the article's on reflection at the codeproject but it wasnt explained clear enough lol.. i can understand pure code just fine though (is that strange?)
jesse M
|
|
|
|
|
I think you are looking for resources, not reflection . That mite help you, unfortunatley I havent worked with it before
Who is this miscrosoft, and what devilish plans have they for us?
|
|
|
|
|
ResourceReader
taken from .Net Sdk Documentation
i found out how too use the ResourceReader/writer but it doesnt cover the problem
<br />
using System;<br />
using System.Resources;<br />
<br />
public class SampleClass<br />
{<br />
public static void Main()<br />
{<br />
IResourceWriter rw = new ResourceWriter("MyResources.resources");<br />
rw.AddResource(@"C:\myPrograms\NetText\icons\icon_10.ico", "Stop");<br />
rw.AddResource(@"C:\myPrograms\NetText\icons\Icon_Question.ico", "Question");<br />
rw.AddResource(@"C:\myPrograms\NetText\icons\Icon_14.ico", "Folder");<br />
rw.Close();<br />
}<br />
}<br />
<br />
i noticed that resource reader only makes a resource file points too a perticular directory / file which doesnt help me...cause im trying too keep my icons hidden so if someone deletes them..the program wont keep throwing exceptions.. and ideas leppie ?
email me at : res1s5yd@verizon.net if u need more info or anything leppie.
jesse M
|
|
|
|
|
OK some more info from MSDN ms-help://MS.VSCC/MS.MSDNVS/cptutorials/html/image_resources.htm[^], sorry I cant help anymore without actually learning how to use resources.
Image Resources
To create image resources, perform the following three steps:
Create an XML-based .resx file containing the named resources.
Convert the .resx file into a .resources file using Resgen.exe.
Create a DLL, and embed the .resources file using the Assembly Generation Tool (AL).
Note For more information on AL, see Appendix B: Resource Tools.
As with strings, if the image resources are localized into nondefault cultures, the process must be done for each culture — which must also be specified when using AL — as well as for a default, language-neutral culture.
The first step — creating the .resx file — is more complicated with image resources. There are several methods for doing this, but ultimately the resource must be converted into ASCII text using BASE64 encoding and embedded into an XML-formatted .resx file.
ResXGen — A handy tool for converting resources is the ResXGen utility included with this tutorial. This small console application takes three arguments: the name of the image file, the .resx output file, and the name to give the resource. The following command line is from the Build.bat file for the Graphic sample application:
ResXGen /i:un.jpg /o:Images.resx /n:flag
A more complete description of this tool, including a discussion of the source code, can be found in Appendix B: Resource Tools.
ResEditor — Another tool for converting resources is the ResEditor utility included with this tutorial. This Windows Forms application allows to you add and delete resources — including bitmaps, icons, and strings — that are located in .resources files. By using a property browser, ResEditor allows you to explore the properties of graphic resources and directly edit string resources.
To illustrate how to use this tool (which might not be completely obvious), you can now walk through the process of creating a common .resources file that combines the German resources from the WorldCalc and Graphic samples discussed earlier. Start ResEditor, and open MyStrings.de.resources from the \de subdirectory of the WorldCalc sample directory for either Visual Basic or C#. Note that the string name/value pairs are listed in the property grid. In the Add group of controls near the bottom of ResEditor, type flag, and click the Add button (which will no longer be disabled). A new node is added to the tree of controls and properties that is on the left. Select the new flag node, and click the ellipsis button (…) that is just to the right. Navigate to the \flags subdirectory of the WorldDocs sample, and specify the de-DE.jpg image file. Note that the properties for the Flag bitmap are now shown as a thumbnail image — in this case, of the German flag. You should now see something like the following illustration.
Resource Editor (RESEDITOR) (from the Appendix B link)
The Resource Editor (ResEditor) sample application is also a useful tool. It provides a graphical interface that allows you to construct .resources files containing bitmaps, icons, and strings.
It appears RESEDITOR is a sample app included with the SDK samples. You might be required to build it 1st.
ANyways hope this helps
PS: JTJ had an article/post a few months back if I remember correctly, not sure if that would help.
Who is this miscrosoft, and what devilish plans have they for us?
|
|
|
|
|
leppie wrote:
JTJ had an article/post a few months back if I remember correctly, not sure if that would help.
Not really, my article covers using VS.NET and the commandline; but I don't know anything about SharpDevelop...but I may have to install it just so I can add more to the article
James
"It is self repeating, of unknown pattern"
Data - Star Trek: The Next Generation
|
|
|
|
|
Jesse,
Not sure if this is exactly what you're looking for, but in addition to what leppie said, you can embed the .resource file (generated by resgen) in your assembly using /res <resource file="" name=""> in your csc command and then read it back again using
Assembly ass = Assembly.GetCallingAssembly();
Stream strm = ass.GetManifestResourceStream("MyResourceFile.resources");
IResourceReader rr = new ResourceReader(strm);
IDictionaryEnumerator de = rr.GetEnumerator();
while (de.MoveNext())
{
} (This requires System.Reflection and System.Resources)
Paul
Pleasently caving in, I come undone - Queens of the Stone Age, No One Knows
|
|
|
|
|
Hi all,
The function below is used to filter out messages in a DataSet depending on wheather they are between the two dates; "DateTime from" and "DateTime to".
The date of the message is the first column of each row.
(logDataSet is a global variable)
I'm having trouble with this line:
tempDS.Tables["Table"].Rows.Add(logDataSet.Tables["Table"].Rows[i]);
in the below code.
I get the following exception:
"System.ArgumentException
This Row already belongs to another table"
Also, I have tried creating an copy of the DataSet logDataSet (DataSet tempDS = logDataSet), but when I delete rows from the copy it seems to also delete these rows from the global DataSet logDataSet.
Does anyone have any ideas where I am going wrong?
Thanks,
Donal
<br />
private DataSet filterDates(DateTime from, DateTime to)<br />
{<br />
DataSet tempDS = logDataSet.Clone();<br />
for(int i=0;i < logDataSet.Tables["Table"].Rows.Count;i++)<br />
{<br />
DateTime fromTime = (DateTime)logDataSet.Tables["Table"].Rows[i][0];<br />
DateTime toTime = (DateTime)logDataSet.Tables["Table"].Rows[i][0];<br />
if( fromTime.Date >= from.Date && toTime.Date <= to.Date)<br />
{<br />
tempDS.Tables["Table"].Rows.Add(logDataSet.Tables["Table"].Rows[i]);<br />
}<br />
}<br />
return tempDS;<br />
}
|
|
|
|
|
I suggest using a DataView as a filter - or -
From MSDN:
DataTable.NewRow Method
See Also
DataTable Class | DataTable Members | System.Data Namespace | AcceptChanges | Add | DataColumnCollection | DataColumn | DataRowCollection
Creates a new DataRow with the same schema as the table.
[Serializable]
public DataRow NewRow();
Return Value
A DataRow with the same schema as the DataTable.
Remarks
You must use the NewRow method to create new DataRow objects with the same schema as the DataTable. After creating a DataRow, you can add it to the DataRowCollection, through the DataTable object's Rows property.
- or -
Copy the value directly from the DataRow's ItemArray property.
Who is this miscrosoft, and what devilish plans have they for us?
|
|
|
|
|
I tried to integrate a flex program with C# the way I used to integrate with VB6 but nothing is happening.
I want to know the correct way to do it. Is there any DLLs I have to attach?
Anybody know abt this? Pls help me.
Thanks.
kind rgds,
Anjana Aluthwala
|
|
|
|
|
If you give more details perhaps someone can help you, if you repost it, no one will. To be honest I dont even know WTF you are talking about , FLEX (is it some kind of aerobics exercise?) never heard of it. VB6 never touched it. Maybe post some VB6 code in the VB.NET forum. Just dont repost!!!!
Who is this miscrosoft, and what devilish plans have they for us?
|
|
|
|
|
I have to write a program in c#,recently. However I don't know what to write about.I think it may be about socket programing. But in fact, there are still too much we can write using sockets. Still, I want to write something new. Can you all help me, and give me some sugguestion? Think you all.
|
|
|
|
|
Anything on Remoting or using Managed DirectX A C# CodeDom codeparser will be nice while you are at it
Who is this miscrosoft, and what devilish plans have they for us?
|
|
|
|
|
I vote for Yacc and Lex.
Вагиф Абилов
MCP (Visual C++)
Oslo, Norway
Hex is for sissies. Real men use binary. And the most hardcore types use only zeros - uppercase zeros and lowercase zeros.
Tomasz Sowinski
|
|
|
|
|
Hi all,
How do I convert the current value of a DateTimePicker control to a DataTime object?
Thanks
Donal
|
|
|
|
|
From MSDN:
DateTimePicker.Value Property
See Also
DateTimePicker Class | DateTimePicker Members | System.Windows.Forms Namespace | DateTime
public DateTime Value {get; set;}
Property Value
The DateTime value assign to the control.
Remarks
If the Value property has not been changed in code or by the user, it is set to the current date and time (DateTime.Now).
Example
The following example demonstrates how use the Value property to retrieve the current date value. First, the example displays the Value property. The example then increments the Value property by one day and displays the property value again.
public MyClass()
{
DateTimePicker dateTimePicker1 = new DateTimePicker();
Controls.AddRange(new Control[] {dateTimePicker1});
MessageBox.Show(dateTimePicker1.Value.ToString());
dateTimePicker1.Value = DateTime.Now.AddDays(1);
MessageBox.Show(dateTimePicker1.Value.ToString());
}
Who is this miscrosoft, and what devilish plans have they for us?
|
|
|
|