I am a newbie in wpf, I am using treeview but there are some different with winform. In treeview, I try to set treeviewItem.Name = "1.1" But it always say invalid. Is there anyway to pass it?
var node = new TreeViewItem();
node.Name = "1.1";
And the error
You can't do it, because of dot in variable name. See General Naming Conventions:
DO NOT use underscores, hyphens, or any other nonalphanumeric
characters.
May be you have wanted to set the Header, not the Name property?
var node = new TreeViewItem();
node.Header = "1.1";
Related
I have a .aspx page with several textboxes, including textboxes with IDs of txtID1, txtID2, txtID3... and so on.
I am attempting populate the textboxes with a data from an XML file by looping through a node list. With each loop, I want to use the FindControl method to locate txtID1 and set its .Text to the value of the id attribute of the first node; then locate txtID2 and its .Text to the value of the id attribute of the second node, and so on.
When the following line of code is run, I get a null reference error for TextBox txtID, so it appears that I am doing something wrong with the FindControl method. Is my syntax incorrect? Do I need to use a different method?
int x = 1;
XmlNodeList getAuthors = getItem.SelectNodes("item/authors");
foreach (XmlNode getAuthor in getAuthors)
{
TextBox txtID = (TextBox)Page.FindControl("txtID" + x.ToString());
txtID.Text = getAuthor.Attributes["id"].Value.ToString();
x = x + 1;
}
After further research (that is, lots of Googling), it appears that I may be running into this problem because I am using a master page. Neither (TextBox)FindControl nor (TextBox)Page.FindControl was working so I have abandoned this approach. Here is an old article that seems to explain my problem.
http://weblog.west-wind.com/posts/2006/Apr/09/ASPNET-20-MasterPages-and-FindControl
I'm developing an application for Windows 8 and am using Hubs and HubSections.
What I'm trying to do is create multiple HubSections depending on the JSON I fetch.
The problem I have is, when I try to set the new HubSection ContentTemplate the program crashes pointing to global::System.Diagnostics.Debugger.Break();
HubSection hs = new HubSection();
hs.ContentTemplate = this.Resources["canteenSectionDataTemplate"] as DataTemplate;
The thing is, if I set hs.ContentTemplate to the ContentTemplate of an already existing HubSection, it works fine, so I'm thinking the problem has to do with the template not being loaded yet?
This won't fix your problem, but it's worth noting that doing this is fairly bad practice for a number of reasons:
HubSection hs = new HubSection();
hs.ContentTemplate = this.Resources["canteenSectionDataTemplate"] as DataTemplate;
Instead of that, when using the as keyword, you should always check for null (unless you know without doubt that it will never be null, in which case you can just cast the value):
HubSection hs = new HubSection();
DataTemplate canteenSectionDataTemplate = this.Resources["canteenSectionDataTemplate"]
as DataTemplate;
if (canteenSectionDataTemplate != null)
hs.ContentTemplate = canteenSectionDataTemplate;
Apart from handling null errors, this code also enables you to check whether the canteenSectionDataTemplate DataTemplate is null or not.
So regarding your question, does the canteenSectionDataTemplate DataTemplate equal null or not? If it does, where is this code being called from? You may need to defer it to make it work.
i'm learning Visual, and i'm tryind to do this:
For Each folder In Dir.Subfolders
list = list + 1
C1CheckBox(list).Text = folder.Name
Next
I have a lot of checkboxex named C1CheckBox1, C1CheckBox2, C1CheckBox3, etc... then i want to change the text of each checkbox by the folder name (using the list var to reference the object)...
How i can do this?
thankyou for read
You can find controls by name with Controls.Find :
For Each folder In Dir.Subfolders
list = list + 1
Dim cb As CheckBox = Me.Controls.Find("C1CheckBox" & list, True)(0)
cb.Text = folder.Name
Next
This will search the entire form including its child containers. If you know all your checkboxes are in say, panel1, you could be more specific:
Dim cb As CheckBox = Me.Panel1.Controls.Find("C1CheckBox" & list, False)(0)
You can loop through all of the checkboxes setting their text as you go. See this answer for an example for how to enumerate the checkboxes
I am trying to manipulate a requested document in the WPF WebBrowser-control. I already managed it to invoke JavaScript on loaded document, but I am not able to change the shown HTML-code in the control itself.
My (very simplified) code in the OnNavigating-Handler looks like this:
mshtml.HTMLDocument doc = (mshtml.HTMLDocument)View.browser.Document;
HTMLTableClass table = doc.getElementById("someTable") as HTMLTableClass;
if (table != null)
{
table.appendChild((IHTMLDOMNode)(doc.createElement("<tr>") as IHTMLElement));
}
doc.close();
The -element doesn't get appended to displayed document in the control.
Any hints are very appreciated!
I finally got it. Its only possible to change the content of the table by adding rows and cells which i wanted to avoid in first place. My approach was to directly change the content of the -tag, which didnt work.
mshtml.IHTMLTableRow row = table.IHTMLTable_insertRow(-1) as mshtml.IHTMLTableRow;
mshtml.IHTMLElement c = (mshtml.IHTMLElement)row.insertCell(0);
c.innerText = "some";
mshtml.IHTMLElement c1 = (mshtml.IHTMLElement)row.insertCell(1);
c1.innerText = "text";
In Silverlight, when you want to create a control dynamically, you must add the namespaces like this (as in http://msdn.microsoft.com/en-us/library/cc189044(VS.95).aspx):
XNamespace xmlns = "http://schemas.microsoft.com/client/2007";
XElement textBlock2 = new XElement(xmlns + "TextBlock",
new XAttribute(XNamespace.Xmlns + "x", "http://schemas.microsoft.com/winfx/2006/xaml"),
...
);
My problem is that I have a user control in its own namespace, so I must write something like
XNamespace myxmlns = "mynamespace";
XElement myelem = new XElement(myxmlns + "MyCtrl", ...
I can then add aliased namespaces like that
new XAttribute(XNamespace.Xmlns + "x", "http://schemas.microsoft.com/winfx")
but I can't figure out how to add the default namespace. I either get a compile error or a run-time error ("AG E PARSER MISSING DEFAULT NAMESPACE"), whatever I try.
I succeeded doing it with building a big string of what I need, but I would like to understand what I am missing.
Any idea?
Thanks.
From the XNamespace docs here:
new XAttribute("xmlns", "http://http://www.adventure-works.com")
Just add it as an XAttribute.