|
Just note: I do NOT want to use reflection to perform this task, because the first use of reflection causes a slow-down, so if I need it to show main menu, then... . I tried to use Xml Serialization system in .Net, but I didn't like it. It's too slow (as it uses reflection) and forces me to design class in a specific style which does not satisfy me. Cheers!
Greetings - Gajatko
Portable.NET is part of DotGNU, a project to build a complete Free Software replacement for .NET - a system that truly belongs to the developers.
|
|
|
|
|
Take a look at XPath and the Node.selectNodes(...) method
led mike
|
|
|
|
|
Ok I get it. Thanks.
public static void FromFile(string path, KorepetytorMenu menu)
{
XPathDocument doc = new System.Xml.XPath.XPathDocument(path);
XPathNavigator nav = doc.CreateNavigator();
if (!nav.MoveToChild("KorepetytorMenu", "")) return;
if (!nav.MoveToChild("RootNode", "")) return;
menu.rootNode = KorepetytorMenuNode.FromXmlNavigator(nav);
ReadNodeChildsRecursive(menu.rootNode, nav);
}
Is it a correct approach?
Greetings - Gajatko
Portable.NET is part of DotGNU, a project to build a complete Free Software replacement for .NET - a system that truly belongs to the developers.
|
|
|
|
|
gajatko wrote: Is it a correct approach?
Well I'm not sure what you are trying to do and that is certainly an improvement, but you still have not used XPath. If you want to access a possible set of elements you can use XmlNode.SelectNodes with an XPath statement and it is possible to get a collection of all the nodes you are interested in and then you simply iterate the list and do whatever operations you need for each XmlNode in the collection. See the example code in the documentation for XmlNode.SelectNodes()
led mike
|
|
|
|
|
Do you think of sth like this?:
static void ReadNodeChildsRecursive(KorepetytorMenuNode rootNode, XPathNavigator nav)
{
XPathNodeIterator iter = nav.SelectChildren(XPathNodeType.Element);
while (iter.MoveNext()) {
if (iter.Current.Name == "Node") {
rootNode.Nodes.Add(KorepetytorMenuNode.FromXmlNavigator(iter.Current));
ReadNodeChildsRecursive(rootNode.Nodes[rootNode.Nodes.Count - 1], iter.Current);
}
}
}
And...
public static KorepetytorMenuNode FromXmlNavigator(XPathNavigator nav)
{
return new KorepetytorMenuNode() {
File = nav.GetAttribute("File", "") ?? "",
Header = nav.GetAttribute("Header", "") ?? "",
Image = nav.GetAttribute("Image", "") ?? ""
};
}
Maybe I should post it in my previous message so it would be clear what did I do.
Greetings - Gajatko
Portable.NET is part of DotGNU, a project to build a complete Free Software replacement for .NET - a system that truly belongs to the developers.
|
|
|
|
|
Why don't you do it the easy way:
string myFileName = @"C:\test\my.xml";
DataTable data = new DataTable();
data.ReadXml(myFileName);
After you've done that, you can just retrieve the data from data.Rows...
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
What about a situation when I have many meaningfull attributes and xml represents a tree with unbounded complexity? I though that a DataTable doesn't support more than a finite number of sub-trees, does it? Maybe I missed something, however.
Greetings - Gajatko
Portable.NET is part of DotGNU, a project to build a complete Free Software replacement for .NET - a system that truly belongs to the developers.
|
|
|
|
|
You could try it and see what happens. That's part of the adventure of being a programmer.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
Hi !,
I am new to C# and was wondering if the standard components included in .NET are usefull enough to build winforms ? Or better buy 3rd class libraries ?
Thanks you !
Best regards,
Steve
|
|
|
|
|
with standard controls, you can develope any application, however nearly all third party controls are for good looking GUI they may slow performance too
and for more info, just google
TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L
%^]*IRXD#@GKCQ`R\^SF_WcHbORY87??6?N8?BcRAV\Z^&SU~%CSWQ@#2
W_AD`EPABIKRDFVS)EVLQK)JKSQXUFYK[M`UKs*$GwU#(QDXBER@CBN%
Rs0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-i?TV.C\y<p?jxsg-b$f4ia>
--------------------------------------------------------
128 bit encrypted signature, crack if you can
|
|
|
|
|
Steve Declerck,
Well, what do you want to do?, If its just simple form that inputs values into a DB, then sure, they are fine. If you want to display models and graphs, then, you'll need to buy some 3rd party libs.
Regards,
Gareth.
|
|
|
|
|
Hi Steve,
The standard .Net components are used to create WinFrom applications. However, it depends on your requirements or scope of your application. If .Net standard components meets your application's requirements then you can use them in your application in case if not then you may try ComponentOne's Studio Enterprise suite and evaluate it and see if those components can meet your requirements. Below is the link for the download.
http://download.componentone.com/pub/Net/c1studionet/Updates/C1StudioNET2_T307_Setup.exe[^]
For more information please visit www.componentone.com
I hope this helps .
Regards,
John Adams
ComponentOne LLC
|
|
|
|
|
Controversial one here, but why develop in WinForms? Take a look at WPF - done properly you can change the look of the app later on. See this[^] post by the WPF meister Josh Smith.
|
|
|
|
|
Hello folks,
Many thanks for the replies, very helpful. Indeed it's for application that inserts data in a DB. I will try the standard components !
Thanks,
Steve
|
|
|
|
|
I'm coding an FTP client in C#, and I'm trying to use System.Net.Socket's BeginReceive method to stop the UI from freezing when receiving data. At present, it works as it should, but whenever there's a transfer in progress (upload/download or directory listing), the UI freezes until it's complete.
I want to use BeginReceive to recive data in a different thread. This is what I have to far:
Two classes - FTP and FrmMain.
In FTP I have a delegate:
<br />
public delegate void DirListDelegate(object sender, ArrayList items);<br />
public event DirListDelegate OnDirListComplete;<br />
The I have three methods:
<br />
private void OnDataReceived(IAsyncResult asyn) {<br />
int bytes = dataSocket.EndReceive(asyn);<br />
bldBuffer.Append(Encoding.ASCII.GetString(buffer, 0, bytes));<br />
if(bytes < buffer.Length) {<br />
dataSocket.Close();<br />
OnDirListComplete(this, itemsList);<br />
} else {<br />
WaitForData();<br />
}<br />
}<br />
private void WaitForData() {<br />
dataSocket.BeginReceive(buffer, 0, buffer.Length, SocketFlags.None, new AsyncCallback(OnDataReceived), null);<br />
}<br />
public void ListDir() {<br />
dataSocket = openSocket();<br />
<br />
bldBuffer.Remove(0, bldBuffer.Length);<br />
WaitForData();<br />
}<br />
Then I call FTP.ListDir() from FrmMain. What should happen is the main program should be free to respond to user clicks etc and not freeze, but it's as though I'm just using Receive instead of BeginReceive.
I'm really stuck on this and I'd appreciate any help.
|
|
|
|
|
Echilon wrote: I'm really stuck on this and I'd appreciate any help.
Hello Echilon and welcome to code project. You posted this problem yesterday and I replied to you. Now you start a new thread of the same subject without ever responding to my reply. That is considered rude and an abuse of the CodeProject resources.
Take a moment to read these posting guidelines[^] along with the first post in this forum titled "How to get an answer to your question".
led mike
|
|
|
|
|
So, the first attempt ended up in the wrong board, so I'm asking again here (hopefully the right board):
I'd like to add an existing Webusercontrol (.ascx) programatically to a class which returns a Webcontrol:
public class ClassName :IHoldtheDefinition
private WebControl AddName()
{
WebControl cntrl = new WbControl();
cntrl.Controls.Add(new Label() {Text="test"});
wuc_anything wuc = new wuc_anything(); //existing Webusercontrol inside the Assembly
cntrl.Controls.Add(wuc);
return wuc;
}
It doesn't throw an exception, but the content is not displayed.
Why I need it this way? I get the class just by it's name (implements an interface) and want to give the possibility to add content to a page by three simple steps.
1. Add the button definition to a xmlfile
2. add a class witch is named as defined in the xml file - the class has to implement the interface and returns a Webcontrol
3. If needed design a WebUserControl and add it programatically to the class as described above.
Help would be apreciated.
|
|
|
|
|
ezazazel wrote: So, the first attempt ended up in the wrong board, so I'm asking again here (hopefully the right board):
Never mind. Albeit it is an ASP.NET question but it figures under C#, the one thing to appreciate is your immediate response by posting it in a more near forum.
A few quick clarifications regarding your snippet:
ezazazel wrote: AddName
If you are invoking through an ASPX page through <% %> function, the exception might just get swallowed. Did you try encompassing the code in a try-catch and from within a CodeBehind. An attached debugger can help you flag out if control has any issues trying to enter the catch block.
ezazazel wrote: IHoldtheDefinition
Were there any warnings thrown during compilation regarding this?
Vasudevan Deepak Kumar
Personal Homepage Tech Gossips
A pessimist sees only the dark side of the clouds, and mopes; a philosopher sees both sides, and shrugs; an optimist doesn't see the clouds at all - he's walking on them. --Leonard Louis Levinson
|
|
|
|
|
I think I located the problem. It seems to be here:
WebControl cntrl = new WebControl
(HtmlTextWriterTag.Div);<---
I tried HtmlTextWriterTag.Object /Unknown and many more.. sometimes I get a blank square, but most of the time nothing.
With the debugger taken a closer look, it reveals to me, that the control is correctly added. It is simply not shown (rendered).
WebUserControl1 wuc = new WebUserControl1();
cntrl.Controls.Add(wuc);
return cntrl;
Here the very essential part of the code, where WebUserControl1 holds a Label:
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
AddCntrlCls cls = new AddCntrlCls();
try
{
this.Controls.Add(cls.AddElement());
}
catch(Exception ex)
{
throw new Exception(ex.ToString());
}
}
}
public class AddCntrlCls
{
public WebControl AddElement()
{
WebControl cntrl = new WebControl(HtmlTextWriterTag.Div);
WebUserControl1 wuc = new WebUserControl1();
cntrl.Controls.Add(wuc);
return cntrl;
}
}
Yes, before I forget - I'm working with a project (WebApplication), therefore I can create instances of Controls, at least to me it ssems so.
|
|
|
|
|
Ah, I finally found a way. Thought too much in C# and not enough in ASP.NET
Here's the way it works:
public class AddCntrlCls : System.Web.UI.Page //Has to inherit from Page
{
public WebControl AddElement()
{
WebControl cntrl = new WebControl(HtmlTextWriterTag.Div);
cntrl.Controls.Add((Control)Page.LoadControl("WebUserControl1.ascx")); //Here is the Magic
cntrl.Controls.Add(new Label() { Text = "I'm a Text" });
return cntrl;
}
}
|
|
|
|
|
i'm working with SQL Server 2005
in my c# App i've got a DataGridView that is bound to a Source(a table in the database)
i can add new row ,delete row but CAN'T Update row Content
this is the code :
this is the event when a buttoncell is clicekd
<br />
private void dgvCarDetails_CellContentClick(object sender, DataGridViewCellEventArgs e)<br />
{<br />
switch (e.ColumnIndex)<br />
{<br />
case 8:<br />
UpdateDataSet();<br />
break;<br />
case 9:<br />
dS_CarManager.T_CarDetails.Rows[e.RowIndex].Delete();<br />
UpdateDataSet();<br />
break;<br />
}<br />
}<br />
<br />
this functions operate as a service function to update<br />
private void UpdateDataSet()<br />
{<br />
TA_CarDetails.Update(dS_CarManager.T_CarDetails);<br />
dS_CarManager.T_CarDetails.AcceptChanges();<br />
}<br />
<br />
<br />
<br />
<br />
Have Fun
Never forget it
|
|
|
|
|
Hello everybody! I have this API published in a C DLL:
int readValue(int objectId, int outputTypeId, void * buf);
Where buf is a pointer to a buffer in memory that can be pretty much anything, depending on the outputTypeId value. In the simplest cases, it points to an int or to a float.
The managed declaration I'm using is:
[DllImport(ReferenceDLL)]<br />
public static extern int H5Aread(int attr_id, int mem_type_id, IntPtr buf);
I have googled a lot and came out with the following solution to get the right value out of that call:
public int GetValueInt32()
{
int value = 0;
GCHandle handleValue = GCHandle.Alloc(value, GCHandleType.Pinned);
DllImports.H5Aread(ObjectId, ImportedDataTypes.H5T_NATIVE_INT, handleValue.AddrOfPinnedObject());
value = (int)handleValue.Target;
handleValue.Free();
return value;
}
public float GetValueFloat()
{
float value = 0;
GCHandle handleValue = GCHandle.Alloc(value, GCHandleType.Pinned);
DllImports.H5Aread(ObjectId, ImportedDataTypes.H5T_NATIVE_FLOAT, handleValue.AddrOfPinnedObject());
value = (float) handleValue.Target;
handleValue.Free();
return value;
}
It works, but I'm a bit puzzled. According to my understanding of how GCHandle should work, it shouldn't be necessary to copy the value of handleValue.Target into value - it's just pinning the address of value to avoid moving. But if omit the copying step, value is always zero.
If this is the way GCHandle is supposed to work, then why I'm passing an instance of value to GCHandle.Alloc instead of the memory size to allocate?
If anyone can shed more light on this topic, I'd be really grateful. My next project is going to use a lot of P/Invokes, and I really need to understand what's going on there.
Is there's a "right" way to accomplish what I'm trying to do?
Luca
The Price of Freedom is Eternal Vigilance. -- Wing Commander IV
En Það Besta Sem Guð Hefur Skapað, Er Nýr Dagur.
(But the best thing God has created, is a New Day.)
-- Sigur Ròs - Viðrar vel til loftárása
|
|
|
|
|
Luca Leonardo Scorcia wrote: Is there's a "right" way to accomplish what I'm trying to do?
I don't know. But from my perspective as a C++ developer I would almost never use PInvoke. I would use a C++/CLI mixed mode class library project to solve all the managed-to-native issues. The resulting assembly would provide a managed class solution for use in C#.
But that's me
led mike
|
|
|
|
|
Hi Luca,
I have used GCHandle many times to pass a reference type from managed C# to unmanaged C code;
I never needed GCHandle.Target since my object was either an instance of a class I created,
or a simple array. What really gets passed on is a memory pointer, pointing to the
managed data (which got pinned down so the GC cannot move it around any more), so the
unmanaged world can manipulate the data in the managed object.
I assume you need GCHandle.Target to get the same result when you pass on a value type
(such as the int and float in your examples); but I cannot confirm that from experience,
and I have never come across any example of GCHandle.Target till now.
However, when you know the argument is a value type, you can declare another prototype
of your unmanaged method using the ref or out keyword, and forget all about GCHandle:
reffing/outing a local value type is OK, since locals are on stack, and stack does not get
moved around, so the following should work:
[DllImport(" ... .dll")]
public static extern void H5Aread(... , out float val);
public int GetValueInt32(){
int value = 0;
DllImports.H5Aread(ObjectId, ImportedDataTypes.H5T_NATIVE_INT, out value);
return value;}
The hearth of the matter is you can overload the method, i.e. have multiple managed method
prototypes with different parameter signatures, but all pointing to the same unmanaged
function.
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
Whoa! This is great news! I didn't think about overloading the method!
The distinction about value types and reference types makes sense. I'll do a few more tests in the evening to understand everything better, but your post shed much more light on this topic. Thanks a lot!
Luca
The Price of Freedom is Eternal Vigilance. -- Wing Commander IV
En Það Besta Sem Guð Hefur Skapað, Er Nýr Dagur.
(But the best thing God has created, is a New Day.)
-- Sigur Ròs - Viðrar vel til loftárása
|
|
|
|
|