|
I've a webservice that returns a TList object and populates the datagrid as follow:
void proxy_CustomerInfoCompleted(object sender, CustomerInfo.CustomerInfoCompletedEventArgs e)
{
datagrid1.ItemsSource = e.Result;
}
It works, but now, what I need to do is to create a local TList copy of the e.result and then bind the newly created object to the datagrid. Is it possible to do it in C#?
Something like:
TList<Customer> = e.Result;
datagrid1.ItemsSource = Customer;
|
|
|
|
|
What is a TList?
e.Result is apparently already a reference to "a local TList copy"
so can't you just assign it to a variable?
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
That is my point exactly!
e.Result is the object that is returned from the Web Service. It is a TList object. But how do I copy it to a local TList object?
|
|
|
|
|
TList mytlist = e.Result as TList;
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Correcting the subject: The e.Result is a List collection and not a TList object as mentioned before.
I need to know how to copy it to another List collection.
I've attempted in a variety of ways but always endup with a compiler error that doesn't accept the e.Result as a valid List
modified on Tuesday, September 1, 2009 6:59 PM
|
|
|
|
|
Have you tried the following?
TList list = new TList();
list.AddRange(e.Result);
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
Your e.Result will most likely be a collection object that inherits from ICollection.
From the threads it looks like it is a List<customer>. If it is then you can simply use
List<Customer> myObjectName = (List<Customer>)e.Result;
Otherwise if you really want to make a copy of the list use LINQ[^]
"A democracy is nothing more than mob rule, where fifty-one percent of the people may take away the rights of the other forty-nine." - Thomas Jefferson
"Democracy is two wolves and a lamb voting on what to have for lunch. Liberty is a well-armed lamb contesting the vote." - Benjamin Franklin
Edbert
Sydney, Australia
|
|
|
|
|
"Your e.Result will most likely be a collection object that inherits from ICollection."
You are right and by watching the compiler error I can see it is from "System.Collections.Generic.IEnumerable" and the List is from "System.Collections.Generic.List" thus the problem.
I've changed the Service Configuration to return a List instead of a collection but it didn't help. The only way to create a local copy of the list returned by the web server was doing the folllowing:
for (int i = 0; i < e.Result.Count; i++)
{
myClass.Add(new myClass()
{
AcctNo = e.Result[ i ].AcctNo,
Name = e.Result[ i ].Name,
Address = e.Result[ i ].Address,
Phone = e.Result[ i ].Phone,
EMail = e.Result[ i ].EMail
});
}
|
|
|
|
|
Since this is Silverlight, when you generate the WCF service reference you can actually select whether you want the web service to use existing class structure in its service definition instead of System.Collections.Generic.List.
To do this right-click on your service reference in the Silverlight project, choose "Configure Service Reference" and on the panel tick on "Reuse types in all referenced assemblies", or if you have a specific assembly pick the specific assembly containing the class definition.
If you do the above the e.Result should be of type ObservableCollection<customer> instead of a generic list.
Hope that helps.
Edbert
Sydney, Australia
|
|
|
|
|
Hello All,
I am working on WPF application with MVP architecture. My question is :
how to get the name of the selected node in a tree? Also, i need to get the name of the parent node that the selected node belongs to.
Node1
A1
A2
A3
A4
Node2
A1
A2
A5
A8
Node3
A1
A2
A9
Asin the treeview, it has 3 nodes and each node having children. If I select the Child A2, from Node3, how can this be stored in a string? and also I should get the parent of this A2(which is Node3).
So, on selection of A2 in Node3, I should have the names of A2 and its parent node.
I am doing it in C#.
Please help me.
Thank You,
Ramm
|
|
|
|
|
You probably need to check the events raised by TreeView. I would expect that a click or select event of some form is raised when the user clicks a node, and the code behind should be able to capture that event, which will likely have a reference to the selected node. Each node in the tree has a parent property that can be used to traverse the tree to its main root. Try a search for TreeView in MSDN and look at the Properties and Events.
|
|
|
|
|
Hi,
I am working on a silverlight project. In this when I try to publish my code It failed and it didn't gave me any error. So I took the old application for which publish is successfull and modified it with the changes in the code. Now the .xap file is now updating my chages and it is displaying the old functionality.
If anyone have any idea to make the publish successfull or update the .xap file , please reply me.
Thanks in advance.
|
|
|
|
|
The old XAP file probably lingers on somewhere in a cache. You could try to rename the XAP file, or add a random number in the source parameter of the object tag like
<param name="source" value="XapFile.xap?12345"/><br />
|
|
|
|
|
![Go to Parent](https://www.codeproject.com/App_Themes/CodeProject/Img/arrow-up24.png) OK, here's an extended version. This code appends the file date/time to the XAP file name. This way you'll keep the caching of already loaded XAP files and you don't have to remember to change the number...
<%@ Page Language="C#" AutoEventWireup="true" %>
<script runat="server">
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
const string XAP = "ClientBin/XapFile.xap";
System.IO.FileInfo fi = new System.IO.FileInfo(Request.MapPath("./" + XAP));
string timeStampXAP = fi.LastWriteTime.ToString("yyyyMMdd_HHmmss");
source.Text = String.Format("<param name=\"source\" value=\"{0}?{1}\" />", XAP, timeStampXAP);
}
</script>
<%@ OutputCache Duration="1" VaryByParam="None" Location="None" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Test</title>
<style type="text/css">
html, body {
height: 100%;
overflow: auto;
}
body {
padding: 0;
margin: 0;
}
form {
height: 100%;
}
#host {
height: 100%;
text-align:center;
}
</style>
<script type="text/javascript" src="Silverlight.js"></script>
<script type="text/javascript">
window.onload = function()
{
document.getElementById('host').focus();
}
function onSilverlightError(sender, args) {
var appSource = "";
if (sender != null && sender != 0) {
appSource = sender.getHost().Source;
}
var errorType = args.ErrorType;
var iErrorCode = args.ErrorCode;
if (errorType == "ImageError" || errorType == "MediaError") {
return;
}
var errMsg = "Unhandled Error in Silverlight Application " + appSource + "\n";
errMsg += "Code: " + iErrorCode + " \n";
errMsg += "Category: " + errorType + " \n";
errMsg += "Message: " + args.ErrorMessage + " \n";
if (errorType == "ParserError") {
errMsg += "File: " + args.xamlFile + " \n";
errMsg += "Line: " + args.lineNumber + " \n";
errMsg += "Position: " + args.charPosition + " \n";
}
else if (errorType == "RuntimeError") {
if (args.lineNumber != 0) {
errMsg += "Line: " + args.lineNumber + " \n";
errMsg += "Position: " + args.charPosition + " \n";
}
errMsg += "MethodName: " + args.methodName + " \n";
}
throw new Error(errMsg);
}
</script>
</head>
<body>
<form id="form1" runat="server" enableviewstate="false">
<div id="host">
<object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="100%" height="100%">
<asp:Literal ID="source" runat="server" />
<param name="onError" value="onSilverlightError" />
<param name="background" value="white" />
<param name="minRuntimeVersion" value="3.0.40624.0" />
<param name="autoUpgrade" value="true" />
<a href="http://go.microsoft.com/fwlink/?LinkID=149156&v=3.0.40624.0" style="text-decoration:none">
<img src="http://go.microsoft.com/fwlink/?LinkId=108181" alt="Get Microsoft Silverlight" style="border-style:none"/>
</a>
</object><iframe id="_sl_historyFrame" style="visibility:hidden;height:0px;width:0px;border:0px"></iframe></div>
</form>
</body>
</html>
|
|
|
|
|
Hi.
A nice idea. But it did not work for me. I use the divelement tools where I can display HTML content. And the content of this divelement controls stopps working by using your methode and does a refresh of the whole page.
|
|
|
|
|
I don't know if zlezj's solution is necessary, but...
During development I've noticed sometimes the browser will use a cached xap
instead of my freshly changed xap, so I just got in the habit of clearing the browser
cache every time I test.
Also make sure your newer xap files are actually overwriting old ones when you
publish.
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Is there a simple way to set the IsChecked state of a CheckBox without invoking any Checked event handlers? I want to set the initial state of a checkbox without invoking the Checked handler unnecessarily.
I know it's as simple as having a flag that the event handler looks at, or unhooking the event handler while I'm initializing the check box state, but that just seems clumsy.
Software Zen: delete this;
|
|
|
|
|
How about:
<CheckBox Content="I'm Checked!" IsChecked="True"/>
or, in code:
theCheckbox.IsChecked = true;
Now, I'm a bit puzzle by what you mean "in the event handler"
You don't set it in the event handler (that would be pointless and against the normal behavior of a checkbox), you get the new value!
A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station....
_________________________________________________________
My programs never have bugs, they just develop random features.
modified on Monday, August 31, 2009 9:00 PM
|
|
|
|
|
Super Lloyd wrote: <CheckBox Content="I'm Checked!" IsChecked="True"/>
I can't set the initial state of the checkbox in the XAML, since the initial state is determined programmatically during the Loaded() event handler for the dialog.
Super Lloyd wrote: Now, I'm a bit puzzle by what you mean "in the event handler"
I'm referring to something like this, where a flag tells the CheckBox Checked() handler whether or not to do its thing:
bool _SettingInitialState = true;
_SettingInitialState = true;
_Checkbox.IsChecked = initial_state;
_SettingInitialState = false;
private void _CheckedHandler(...)
{
if (!_SettingInitialState)
{
}
}
Software Zen: delete this;
|
|
|
|
|
why don't you set it in the Loaded event handler then, if it's when it is decided?
A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station....
_________________________________________________________
My programs never have bugs, they just develop random features.
|
|
|
|
|
That's where I want to set it. I'd just like the act of setting the initial state to not trigger the Checked handler when I do so.
Software Zen: delete this;
|
|
|
|
|
Mmm, strange, why is it you can't decide of the checked state before, maybe you are not doing something the elegant way perhaps?
Anyway, to suggest an other unelegant workaround, why don't you register the event handler by code in the Loaded event handler (after setting the value), instead of registering it in XAML?
A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station....
_________________________________________________________
My programs never have bugs, they just develop random features.
|
|
|
|
|
Super Lloyd wrote: Mmm, strange, why is it you can't decide of the checked state before, maybe you are not doing something the elegant way perhaps?
Setting the state depends upon communications with an external process, which may take a significant amount of time. Until that communication completes, I don't know the state.
I may simply connect the event handler when the communication completes, instead of in the Loaded() handler.
Thanks for the suggestions .
Software Zen: delete this;
|
|
|
|
|
Hi
I have an enum set say tiger=0,
lion=1,
deer=2,
snake=4
These enums are to be displayed in a list box which is dependent on a combo box. The combo box will have values like carnivores,herbivores,repltiles.
So when I change my selectedindex the value in the list box(ie the animal names) should also change. So if I have carnivores, I get lion and tiger. If i have reptiles , I have snake.
Please suggest the respective xaml and the necessary code required. Its very urgent.
Thanks
|
|
|
|
|
So how do you tell from the enum whether the animal is a carnivore? You can't, so you have to..."Its very urgent.". Of course it's urgent to you, but not to everyone else here who volunteer their time. Don't be rude.
only two letters away from being an asset
|
|
|
|