|
If you select a node using the XmlDocument instead of the DocumentElement , you must use a beginning "/" which uses a scope from the root element. The following sample works fine:
using System;
using System.Xml;
public class Test
{
static void Main()
{
XmlDocument doc = new XmlDocument();
doc.Load("Test.xml");
XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable);
nsmgr.AddNamespace("soap", "http://schemas.xmlsoap.org/soap/envelope/");
nsmgr.AddNamespace("l", "http://www.domain.com/EP/");
XmlNode logonNode = doc.SelectSingleNode(
"/soap:Envelope/soap:Body/l:Logon", nsmgr);
if (logonNode != null)
{
foreach (XmlNode child in logonNode.ChildNodes)
Console.WriteLine("{0}: {1}", child.Name, child.InnerText);
}
}
}
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I want that while editing the textBox when I reach the edge
of the column to automaticly start a new line and when
finished that the text will be displayed that way.
|
|
|
|
|
I'm pulling out what little remaining hair I have again. I have a list box with 8 items, the selected item is highlighted at the top of the list. I press a button (cmdMoveDown) and wish to move the selected item 1 item down the list.
I tried this:
public void MoveDown()<br />
{<br />
int index = this.lstSelected.SelectedIndex;<br />
int newindex = index + 1;<br />
<br />
DataTable dtSelect = (DataTable)this.lstSelected.DataSource;<br />
DataRow dr = dtSelect.Rows[index];<br />
<br />
dtSelect.Rows.Remove(dr);<br />
dtSelect.Rows.InsertAt(dr, newindex);<br />
}
this removes the item at index 0 just fine. But the insert doesn't happen and there is a blank line at the bottom of the list.
then i tried this variation:
public void MoveDown()<br />
{<br />
int index = this.lstSelected.SelectedIndex;<br />
int newindex = index + 1;<br />
<br />
DataTable dtSelect = (DataTable)this.lstSelected.DataSource;<br />
DataRow dr = dtSelect.Rows[index];<br />
DataRow drNew = dtSelect.NewRow();<br />
<br />
foreach(DataColumn dc in dtSelect.Columns)<br />
drNew[dc.ColumnName] = dr[dc.ColumnName];<br />
<br />
dtSelect.Rows.Remove(dr);<br />
dtSelect.Rows.InsertAt(drNew, newindex);<br />
}
this variation removed the selected item and added the new row at the end of the list rather than at new index.
I tried various permutations of this code and could get nothing to work. Any suggestions?
|
|
|
|
|
A lot of this depends on how your data source is bound to the ListBox . When you update your DataTable like that, the changes may not be reflected in the ListBox . See the CurrencyManager for more information about a way to refresh the bindings, like calling Refresh on the CurrencyManager you can get from the ListBox.BindingContext (inheritted from the Control class).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Okay. I traced through the previously posted code and the data is actually being inserted into the table correctly and at the correct position. It is the DefaultView which is causing the list to display in the wrong order.
I added the following to the method:
CurrencyManager cmSelect = (CurrencyManager)this.lstSelected.BindingContext(dtSelect);<br />
cmSelect.Refresh();
It runs without error, but nothing changes. Can anyone suggest another approach?
|
|
|
|
|
Then create a DataView on the table and set that as the DataSource .
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I'm Developing a WebApplication in which i have to pass parameter to DLL present in a remote computer and return the values returned by the DLL to the user... someone please help me in doing this....
|
|
|
|
|
You can't load a DLL from a remote computer and have it executed on the remote computer. You need some sort of RPC (remote procedure call), such as DCOM, COM+, .NET Remoting (preferred in .NET applications), or Web Services (if the other machine has IIS installed). In those cases you could P/Invoke the exported function from that DLL (if it's native), thus wrapping the unmanaged function in a managed class (or a native DCOM or COM+ executable).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi,
I was thinking of combining a Diffgram Dataset with using Web Services. From my readings I noticed that I can save a dataset as a diffgram to a file after I do updates/inserts/deletes on the dataset. Then when I need to do more updates/inserts I reread the diffgram into a dataset and if I am connected to a database then use a dataadapter to update the database with changes. Is this correct in my assumption of how I can use the diffgram? I would create a Web Service to accept the Diffgram Dataset and have it create a DataAdapter to update the database. How does this sound? Any ideas?
Thanks,
JJ
|
|
|
|
|
You could do this with a diffgram, but the DataSet and DataAdapter derivatives already support changes. Lets say that your client made changes to a DataSet it original got from a web service. To send the changes call DataSet.GetChanges to get just the changes (optionally, but decreases bandwidth consumption) and then pass the DataSet back to the web service. The web service could call DataAdapter.Update on the DataSet and optionally return the DataSet back to the client (in case there were changes made by other clients, etc.
Just be sure you don't call AcceptChanges otherwise all change information is lost. DataAdapter.Update does this automatically after updating the database. The DataAdapter should have all four command properties defined, and it's common to combine an INSERT and SELECT statement (separated by a semi-colon (;)) so that any auto-generated information (or default values) are included in the DataSet .
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi Heath,
Ok, but this is for an alternative to my semi Offline connection problem. So I would try to contact a web service sitting on the server and if it can't make a connection then have the dataset write out to a diffgram xml file. If I can make a connection then send Diffgram dataset to web service to update database by using DataAdapter in web service. How does that sound, Heath?
Thanks,
JJ
|
|
|
|
|
Fine, but why write-out the diffgram at all, unless you're worried about your application being closed. That's understandable.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
ok, I'm not worried about the App being closed. But if connection can't be made to web service on server where do I store the dataset once data is entered in app? I assume just use a normal dataset if not going with diffgram to store locally? Also if I did use a diffgram dataset, this would be the same as replication to database on server. The web service dataadapter would check changes and only pass the inserts/updates etc. to db.
JJ
|
|
|
|
|
Just keep it in memory as an object and keep adding/updating/deleting rows. Once a connection can be established, then send the diffgram (remember, don't ever call AcceptChanges or you won't have a diffgram! ). If you want to save this in case the application is closed, make sure you write out the diffgram using XmlWriteMode.DiffGram and read it back in later.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Ok now I got what you are saying. Yes the application will be closed once done entering in info. This is done on a daily basis and having the PDA on all day doesn't make sense.
Thanks Heath,
JJ
|
|
|
|
|
Note, just because a PDA appears off doesn't mean the memory state isn't saved. This is how they work - unless you physically turn off the device, it is always on - it is just sleeping or hibernating. When you turn it on, every program is still running as it was before. How do you think they can notify you of events when they appear off?
Also, even when you close an application using the X button at the top, the application is still running (unless you're using a single process build of Windows CE - but PocketPC is a multi-process build). It isn't terminated unless you use the Memory control panel app to terminate it or your program terminates itself (or has a critical error and dies).
A few things to keep in mind.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hello all,
My requirement:: There's protocol Interface class with some persistant data which has to be invoked from seveal other classes with out disturbing the Member data. In Visual C++ windows application we create new instance of Protocol Class in the Application main class.... & gets reference of this where ever we are using it.... like
CProtocolAPI *pProtocol = (TestApp*)AfxGetApp()->m_pProtocol
and we can call methods of CProtocolAPI using pProtocol reference
now my doubt is how can i do this in C#.... can any body give me some idea..... little urgent plzzzzzzzzz
Thanku in advance
Adi
|
|
|
|
|
Store a static instance of ProtocolInterface inside your main class and create a static property to access it.
<br />
public class Main<br />
{<br />
private static ProtocolInterface protocol;<br />
public static ProtocolInterface Protocol<br />
{<br />
get<br />
{<br />
return Main.protocol;<br />
}<br />
}<br />
}<br />
Access the instance by Main.Protocol
Does this help?
|
|
|
|
|
I have three forms a parent form, child form 1, child form2. Child form1 is a user interface used to save data to the random access file .The user inputs the following in to the textboxes Name, Account Number, & Address. Child form2 reads the file. That works fine but I would like to use a combobox to display the name and account number, so when the user selects the name & account nuber the textboxes are filled with the appropriate data. Is this possible? Any help would be greatly appreciated.
|
|
|
|
|
my way:
public dataset owned by parentform, with all the data you need in both childs. So even if user changes data from 1st child, data in the 2nd one are immediately available. That's a little faster: no need to save/read/synchronize two datasources. And no need to write your own save to file/load/parse etc. stuff.
h.
|
|
|
|
|
I am importing data from a excel sheet to a listview box. I need to set the range of the listview column to the no of columns available in the excel sheet.
I am able to count the available no of columns in the excel sheet using worksheet.columns.count.
The worksheet.get_range(object cell1, object cell2) asks for the the starting column ie A to the end column which could be anything from B to ZZ and so on.
The solution I could see is add the worksheet.column.count value to 65(ascii code of A). But how do i convert back the value say 77 to its equivalent Ascii char M. I dont find any toascii() function.
Regards
Tarakeshwar
CCIE Q(Routing and Switching), MCSE Security
|
|
|
|
|
You can cast from an int to a char and back again. You don't need any such toascii function.
IIRC, you can just use the string references for the Range object. You could then just enumerate through the collection returned and put the cell values in the ListView according to their index in the collection.
Finally, I'm not sure about your implementation, but have you consider just embedded the Excel ActiveX control in your application?
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I have created a tree and need to add nodes to it, around 28,000 of it. I get the data from the sql database and using dr check for the four different types. According to the type I display the first type first with a color, then the next type with a diff color and so on for the four types of data. The time it takes to load the tree is around 12 secs, but I cant afford more than 5 secs for the task. I have used Treeview.BeginUpdate and Treeview.Endupdate in the code.
Is there any other method to make sure that the tree listing takes place even faster.
Regards
Tarakeshwar
CCIE Q(Routing and Switching), MCSE Security
|
|
|
|
|
Calling BeginUpdate and EndUpdate is about the only thing you can do if you want to load all nodes at the same time. Even using threading, you'll have to use TreeView.Invoke (inheritted from Control ) to add the TreeNode in the thread on which the TreeView was created (necessary, or you'll get strange problems if it even works at all). This still means that adding the tree nodes is synchronous, although initializing the tree nodes can happen in a separate thread (though this probably won't give you the 7 seconds you need).
If you don't need to load the entire tree, I recommend handling the TreeView.BeforeExpand event to implement an on-demand tree.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I agree that TreeView.BeforeExpand is the best solution. Loading 28,000 nodes will take a long time.
Have you tried timing your method to see if it takes 12 seconds for the tree to populate or to reterieve the data from database?
If it's tree loading, you can just load all the data, keep it in some data structure and populate tree with BeforeExpand.
|
|
|
|