|
By adding a MenuItem instance rather than just a string you can do it this way
using System;
using System.Windows;
using System.Windows.Controls;
namespace WpfApplication1
{
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
System.Windows.Controls.ContextMenu cm = new ContextMenu();
MenuItem item = new MenuItem();
item.Header = "test";
item.Click += new RoutedEventHandler(item_Click);
cm.Items.Add(item);
this.ContextMenu = cm;
}
void item_Click(object sender, RoutedEventArgs e)
{
MenuItem item = (MenuItem)sender;
Console.WriteLine(item.Header);
}
}
}
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Expect everything to be hard and then enjoy the things that come easy. (code-frog)
|
|
|
|
|
Thanx dave,
ill have a look and let you know how it goes
Harvey Saayman - South Africa
Junior Developer
.Net, C#, SQL
you.suck = (you.passion != Programming)
|
|
|
|
|
I have a challenge to you all!
I have found a strange (and really annoying!!) behavior when trying to databind a combobox to a property witch is pointing to an interface.
I have the following interface and class:
IPerson.cs:
public interface IPerson
{
string Name { get; set; }
}
Person.cs:
public class Person : IPerson
{
public Person(string name)
{
Name = name;
}
public string Name { get; set; }
public override string ToString()
{
return Name;
}
}
Then I have a form witch contains one ComboBox (comboBox1) and one TextBox (textBox1). The Form1.cs looks like this:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.CurrentPerson = new Person("Person 1");
comboBox1.Items.Add(this.CurrentPerson);
comboBox1.Items.Add(new Person("Person 2"));
comboBox1.Items.Add(new Person("Person 3"));
comboBox1.Items.Add(new Person("Person 4"));
comboBox1.DataBindings.Add("SelectedItem", this, "CurrentPerson");
textBox1.DataBindings.Add("Text", CurrentPerson, "Name");
}
public IPerson CurrentPerson { get; set; }
}
Now to the strange part. If you run the application, change the combobox to "Person 2", and focus the textbox so that the databinding should be triggered, you will see that the combobox is reset to "Person 1"! Why isn't the CurrentPerson changed to "Person 2" instead?
If you let CurrentPerson be a Person, not an IPerson, everything works just fine.
And one more thing... If you add a SelectedIndexChanged event to the combobox, and let it do the databinding, you will find that it is impossible to change the selected item!
Code:
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
Console.WriteLine("Before: Combo:" + comboBox1.SelectedItem.ToString() +
", Current Person: " + CurrentPerson.ToString());
comboBox1.DataBindings[0].WriteValue();
Console.WriteLine("After: Combo:" + comboBox1.SelectedItem.ToString() +
", Current Person: " + CurrentPerson.ToString());
}
If you try to change the selected item from "Person 1" to "Person 3", you get this output:
Before: Combo: Person 3, Current Person: Person 1<br />
Before: Combo: Person 1, Current Person: Person 1<br />
After: Combo: Person 1, Current Person: Person 1<br />
After: Combo: Person 1, Current Person: Person 1<br />
Expected would be:
Before: Combo: Person 3, Current Person: Person 1<br />
After: Combo: Person 3, Current Person: Person 3
Anyone have any clue what I can do to make this work? (Besides doing the binding manually, of cource...)
Thanks in advance!
|
|
|
|
|
I must admit I haven't tried this, but from what I see the textbox is always bound to the object refered to by CurrentPerson at the time of binding. Are you sure that the text values in the dropdown aren't changing as a result of the text in the textbox being pushed back into the new CurrentPerson?
I'm largely language agnostic
After a while they all bug me
|
|
|
|
|
Thanks for answering!
Yes, I am sure that is not the case. The textbox is just there so I have something else to give focus to. The only reason this is databound, is for testing purpose. (That databinding actually works as it should.) My original case was without the textbox.
It seems that the problem occures when the databinding object tries to set
CurrentPerson = (IPerson)comboBox1.selectedItem;
(or whatever syntax the databinding use.) If I implement this line of code when selected item is changed, it all works just fine.
Any other ideas? I am really stuck here
|
|
|
|
|
Problem solved! (At least workaround found...)
If you are interested in the solution, take a look at http://www.devexpress.com/Support/Center/p/Q182427.aspx
|
|
|
|
|
Hi
i use this code to iterate through each procedure in current database :
foreach (Microsoft.SqlServer.Management.Smo.StoredProcedure sp in server.Databases[database].StoredProcedures)
{
if(!sp.IsSystemObject)
sps.Add(sp.Name);
}
but when i add if(!sp.IsSystemObject) statement, my app hangs and crash. why this problem occurs and how to solve it?
thanks
|
|
|
|
|
Try with else instead of !
if(sp.IsSystemObject) // this line
{
}
else
{
sps.Add(sp.Name);
}
pls let me know the result
Thanks
Raja.S
|
|
|
|
|
Thanks Raja
i test your code, but my app has still crash.
|
|
|
|
|
is that showing the exception or just closing the application if possible can you give me the stack trace ?
Thanks
Raja.S
|
|
|
|
|
not any exception, just crash, here is my source code to explore what is my method:
private void GetDatabaseSps(TreeView tree, TreeNode spsNode, string sqlServerInctance)
{
List<string> sps = new List<string>();
string database = spsNode.Parent.Text;
Microsoft.SqlServer.Management.Smo.Server server = new Microsoft.SqlServer.Management.Smo.Server(sqlServerInctance);
foreach (Microsoft.SqlServer.Management.Smo.StoredProcedure sp in server.Databases[database].StoredProcedures)
{
if (sp.IsSystemObject)
{
}
else
{
sps.Add(sp.Name);
}
}
spsNode.Nodes.Clear();
foreach (string str in sps)
{
TreeNode spNode = new TreeNode(str);
spsNode.Nodes.Add(spNode);
}
}
|
|
|
|
|
Can you tell me ,is this happening with SQL 2005 with SP2 and also visual studio 2003 or 2005 ?
Thanks
Raja.S
|
|
|
|
|
hai all ,
we used below method for get the image data from database,it is working fine in desktop computers ,but it is not working in laptops.it is showing below error only in laptops.
Error Message:
out of memory:at System.image.fromfile(string filename,boolean useembeddedcolormanagement) at System.Drawing.image.fromfile(String Filename)
Please help me.
public void getimages()
{
bigImgLst_Vendors.Images.Clear();
smallImgLst_Vendors.Images.Clear();
string path;
path = Path.GetDirectoryName(
Assembly.GetExecutingAssembly().GetName().CodeBase);
path = path.Replace("\\bin\\Debug", @"\Transaction\Contacts\Photos");
path = path.Replace("file:\\", "");
string imageDirectoryPath = path;
string[] files = null;
if (Directory.Exists(imageDirectoryPath))
files = Directory.GetFiles(imageDirectoryPath);
if (files != null)
if (files.Length > 0)
for (int i = 0; i <= files.Length - 2; i++)
if (File.Exists(files[i]))
{
//foreach (ListViewItem vcontext in lvw_VendorList.Items)
//{
//if(vcontext.Tag == (files[i].Split('\\'))[files[i].Split('\\').Length - 1])
bigImgLst_Vendors.Images.Add((files[i].Split('\\'))[files[i].Split('\\').Length - 1],
Image.FromFile(files[i]));
smallImgLst_Vendors.Images.Add(
(files[i].Split('\\'))[files[i].Split('\\').Length - 1], Image.FromFile(files[i]));
//}
}
int imageIndex = -1;
int NoImageIndex = 0;
NoImageIndex = bigImgLst_Vendors.Images.IndexOfKey("NoImage.png");
lvw_VendorList.LargeImageList = bigImgLst_Vendors;
lvw_VendorList.SmallImageList = smallImgLst_Vendors;
lvw_VendorList.StateImageList = smallImgLst_Vendors;
foreach (ListViewItem vcontext in lvw_VendorList.Items)
{
if (vcontext.Tag != null)
if (vcontext.Tag.ToString().Trim() != "")
imageIndex = bigImgLst_Vendors.Images.IndexOfKey(vcontext.Tag.ToString());
if (imageIndex != -1)
vcontext.ImageIndex = imageIndex;
else
vcontext.ImageIndex = NoImageIndex;
imageIndex = -1;
}
}
|
|
|
|
|
It has nothing to do with Laptop or Desktop.
I also had to write code that generating thumbnails some time ago. .NET throws OutOfMemoryException if it does not recognize the image format.
This happen for example when loading the image file whose format is unreconized/unsupported by .NET. Methods might raise this exception
include Image.FromFile, Bitmap constructor, etc, see their "remark" section. You should debug your app to see if it is the cause.
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|
|
Correction to my previous post.
I have created a windows application.
There are forms inside the windows form application project. There is a class library project too.
The .sln is in the following path:
C:\Work\Developments\SQLchecks\SQLchecks
The windows forms are inside the windows application project as below:
C:\Work\Developments\SQLchecks\SQLchecks\SQLchecks
There is a class library project called DataAccess which has classes and an xml file called Settings.xml :
C:\Work\Developments\SQLchecks\SQLchecks\DataAccess
Question:
from within a class inside the DataAccess project which is a class library project, how do I refer to the Settings.xml file which is also in the same directory?
Thanks
|
|
|
|
|
This is just plain rude to the other posters, and you can always modify your original post.
|
|
|
|
|
|
I agree. There is nothing more annoying that the one message board for our local mountain communities that some knitwits post something like *Bump* just to keep the thread alive. Some of the threads died for a reason
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
"Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham
|
|
|
|
|
hello,
i just want to know how can i create a Progressbar that represent the progress of a specific Form.
i mean, i have a Form with a lot of steps..that caculate a lot of things.
while wating that this progress will finish, i want to see the progress in the progressBar..
How can i do it?
thank you
|
|
|
|
|
Add the progress bar component to the form that you want to show it on. Set the maximum value to the number of steps you need to perform, and increment the value by 1 after each step completes.
|
|
|
|
|
DO you have any link that shows to me how to do it?
thank you
|
|
|
|
|
Admin887 wrote: DO you have any link that shows to me how to do it?
Really. Do I need to put a link on here for you? Why don't you try it out for yourself, as this is the best way to learn?
|
|
|
|
|
Thank you..it was very helpful..
|
|
|
|
|
|
Put a ProgressBar on the form and modify the Value property according to the progress that it is being made. You'll have to calculate that as a percentage yourself. (assuming that you show it like x %)
|
|
|
|