|
|
thanx alot , and what is the purpose of combo box ?
|
|
|
|
|
|
could u please give me /provide me the correct version ? i would be really thankful to you .
|
|
|
|
|
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
string s;
s=comboBox1.SelectedItem;
switch(s)
{
case "1":
Form2 f=new Form2();
f.Show();
break;
case"2":
Form3 a=new Form3();
a.Show();
break;
}
}
}
}
its giving me some error
|
|
|
|
|
Having read your original code, and the dialog between you and Colin (and admired Colin's patient responses), I want to offer you what I hope you will experience as constructive advice:
I believe you need to get a good book on C#, and really review the basics of the language Types, and, in WinForms, review the various common controls, like ComboBox, etc.
I'd suggest either the latest version of Jesse Liberty's 'Programming C#' (O'Reilly), and, for WinForms, I'd recommend the 2004 edition of Matthew MacDonald's "Pro .NET 2.0 Windows Forms and Custom Controls in C#" (APress) since I think Matthew has a certain "genius" for teaching and building slowly from fundamental concepts. There are, of course, other books on WinForms from Chris Sells (Addison-Wesley), Erik Brown (Manning).
In asking questions on CP, I'd suggest you begin the question with a clear statement of the context you are working in (WinForms ? WPF ? ASP.NET ?), and then a clear statement of what your goal is.
This goal statement can be very general: like: "I want to have a way at run-time in my WinForms application to select a certain type of Form to be created and shown."
best, Bill
"Last year I went fishing with Salvador Dali. He was using a dotted
line. He caught every other fish." Steven Wright
|
|
|
|
|
I am using XDocument to build XML and writing it out using the Save method - I am having all hell on trying to get it to output a pound (£) sign. I have tried different encodings, tried using XmlWriter etc but nothing seems to work.
I have spent all morning reading articles (mainly others asking the same question with not really anything in the way of a reply which works) so how do I get a pound sign into XML? Currently the easiest option appears to be contacting the treasury and asking them to move to the dollar.
|
|
|
|
|
It's has been a while, but can you write out its unicode value of U+00A3?
|
|
|
|
|
I suppose so, do I have to check every single string built into the XML through XDocument and replace pound signs with that?
|
|
|
|
|
I'll see if I can find how we did it in my code base - it was a copy of years ago that I last worked on the xml generator
|
|
|
|
|
Thanks, any help will be much appreciated
|
|
|
|
|
I had a dig around and couldn't find anything in particular for £ signs - so I created this quick stub and it is working as expected for me
XmlDocument doc = new XmlDocument();
XmlNode node = doc.CreateNode(XmlNodeType.Element, "PoundTest", "Dummy");
node.InnerXml = "£";
doc.AppendChild(node);
doc.Save(@"c:\dummy.xml");
which outputs
<PoundTest xmlns="Dummy">£</PoundTest>
|
|
|
|
|
Hmm, the issues I am having are in an attribute and I am using XDocument rather than XmlDocument.
It's interesting yours works though
|
|
|
|
|
Sorry misread the XDocument bit, just added this to my original stub and it still works though
XmlAttribute elem = doc.CreateAttribute("PoundAttribute");
elem.Value = "£";
node.Attributes.Append(elem);
to give
<PoundTest PoundAttribute="£" xmlns="Dummy">£</PoundTest>
|
|
|
|
|
Thanks. Time to scrap XDocument then
|
|
|
|
|
Here you go
XDocument doc = new XDocument();
XElement node = new XElement("PoundTest", "");
XAttribute attrib = new XAttribute("PoundAttribute", "£");
node.Add(attrib);
doc.Add(node);
doc.Save(@"c:\dummy.xml");
which gives
<?xml version="1.0" encoding="utf-8" ?>
<PoundTest PoundAttribute="£" />
|
|
|
|
|
That works for me too.
Curiouser and curiouser.
Thanks for your help
|
|
|
|
|
Glad I could help - I lived just outside Garforth for 8 years and had many a good night out in Leeds
|
|
|
|
|
Party central is Leeds although it's a long time since I used to haunt the Phono and the Warehouse
|
|
|
|
|
You helped to fix it. You showed the problem wasn't in XML but in the StreamReader I am using to read the data I build into XML - you have to set Encoding on the StreamReader to Encoding.Default - apparently the default isn't Encoding.Default - Bah!!!
|
|
|
|
|
Haha yeah I've tripped over this one a few times. The default is UTF8, I believe. Took me a while to work out that to read a Windows-ANSI file (what most of us actually have on our disks) you have to set it to Default explicitly.
|
|
|
|
|
The default it provides isn't default enough apparently
|
|
|
|
|
It's high-bit so you need to encode it, but the XDocument should do that for you (and Reiss's answer would seem to indicate that that is already the case). The named entity is £ but that only applies in HTML, in XML you would have to use £ or set the declared document encoding to ISO-8859-1 (if there are no 2-bit characters) or UTF-8 (encoding the high bit characters appropriately) in the XML header.
|
|
|
|
|
It took Google years to fix it, finally, (as of this week, they did)
|
|
|
|
|
Hai,
Please take a look my code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Runtime.InteropServices;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace Combo
{
public class Combo
{
private System.Windows.Forms.ComboBox li = new System.Windows.Forms.ComboBox();
public event EventHandler SelectedIndexChanged;
private object[] eventObject;
public void Addselect(Control FormName, string name, int top, int left, int width, int height, string Text)
{
li.Top = top;
li.Left = left;
li.Width = width;
li.Height = height;
li.Name = name;
li.FlatStyle = FlatStyle.Flat;
li.Text = Text;
li.IntegralHeight = false;
li.MaxDropDownItems = 5;
li.DropDownStyle = ComboBoxStyle.DropDown;
li.Size = new System.Drawing.Size(136, 81);
li.BackColor = System.Drawing.Color.DarkGray;
FormName.Controls.Add(li);
eventObject = new object[] { this, "SelectedIndexChanged" };
li.SelectedIndexChanged += new EventHandler(li_SelectedIndexChanged);
}
private void li_SelectedIndexChanged(object sender, EventArgs e)
{
if (SelectedIndexChanged != null)
{
SelectedIndexChanged(eventObject, null);
}
}
public bool Enabled
{
get { return li.Enabled; }
set { li.Enabled = value; }
}
public bool Visible
{
get { return li.Visible; }
set { li.Visible = value; }
}
public void Addtocombobox(string [] arguments )
{
li.Items.AddRange(arguments);
}
public int sindex()
{
int index;
index = li.SelectedIndex;
return index;
}
}
}
The problem is
public int sindex()
{
int index;
index = li.SelectedIndex;
return index;
}
when i try to return the selected index of combobox i got error here please hep me to do fix this error
This is my error please take a look this
Error 1 Since 'Combo.Combo.sindex()' returns void, a return keyword must not be followed by an object expression F:\SelectboxLibrary\SelectboxLibrary\Class1.cs 65 13 SelectboxLibrary
i dont know what is the error
Anyone Please help me?
Arunkumar.T
|
|
|
|