|
Hi,every one
How can we change the combobox look in Wpf?
what I mean in here is to change it from rectangle into ellipse.
thank you all in advance.
modified 25-Aug-12 17:47pm.
|
|
|
|
|
|
Hello
I am trying to write a program to input and display 10 employee details using indexers.I am stuck please help.
[code]
using System;
namespace EmployeeIndexer
{
class Employee
{
string[] edept=new string[10];
string[] ename=new string[10];
int[] eno=new int[10];
int[] esal=new int[10];
int index = 0;
public Employee()
{
edept[index] = "";
ename[index] = "";
eno[index] = 0;
esal[index] = 0;
}
public void AddRec(string d, string n, int no, int s)
{
edept[index] = d;
ename[index] = n;
eno[index] = no;
esal[index] = s;
}
public void this[int pos]
{
get
{
Console.WriteLine("{0} {1} {2} {3}",edept[pos],ename[pos],eno[pos],esal[pos]);
}
}
}
class Employee_List
{
Employee[] e;
int size=0;
public Employee_List()
{
e = new Employee[10];
}
public void AddFunc()
{
string n, d;
int s, no;
Console.WriteLine("Enter the number of records you want to add:");
size = Int32.Parse(Console.ReadLine());
for (int i = 0; i < size; i++)
{
Console.WriteLine("Record Number {0}",i);
Console.WriteLine("Name:");
n = Console.ReadLine();
Console.WriteLine("Number:");
no = Int32.Parse(Console.ReadLine());
Console.WriteLine("Dept:");
d = Console.ReadLine();
Console.WriteLine("Salary:");
s = Int32.Parse(Console.ReadLine());
e[i].AddRec(d,n,no,s);
}
}
public void Disp()
{
for (int i = 0; i < size; i++)
{
Console.WriteLine("Record Number {0}",i);
Console.WriteLine(e[i]);
}
}
}
class Main_Class
{
public static void Main()
{
while (true)
{
Console.WriteLine("Menu");
Console.WriteLine("1.Add 2.Display 3.Exit");
Console.WriteLine("Choice:");
int c = Int32.Parse(Console.ReadLine());
switch (c)
{
case 1:
Employee_List el = new Employee_List();
el.AddFunc();
break;
case 2:
Employee_List e2 = new Employee_List();
e2.Disp();
break;
case 3:
return;
}
}
}
}
}
I am new to C# so pardon my mistakes.
[/code]
|
|
|
|
|
ripples wrote: I am stuck
Do you really think that this is a very good description of your problem?
Why is common sense not common?
Never argue with an idiot. They will drag you down to their level where they are an expert.
Sometimes it takes a lot of work to be lazy
Please stand in front of my pistol, smile and wait for the flash - JSOP 2012
|
|
|
|
|
The easiest way to have indexers available to a class is to derive from an object that already has them, such as List<T>.
A simple example:
public class EmployeeData
{
private string name;
private string department;
public EmployeeData(string name, string department)
{
this.name = name;
this.department = department;
}
public string Name
{
get { return name; }
}
public string Department
{
get { return department; }
}
public override string ToString()
{
return string.Format("{0}, {1}", name, department);
}
}
public class Employee : List<EmployeeData>
{
public Employee(EmployeeData data)
: base(new EmployeeData[] { data })
{ }
}
Employee employee = new Employee(new EmployeeData("Fred", "Reception"));
employee.Add(new EmployeeData("George", "IT"));
List<Employee> employees = new List<Employee>();
employees.Add(employee);
foreach (Employee employeeItem in employees)
{
foreach (EmployeeData employeeData in employeeItem)
{
Console.WriteLine(employeeData);
}
}
If you don't want to expose your class as a List then you can wrap it and expose the parts you want using your own indexers:
public class Employee : IEnumerable<EmployeeData>
{
private List<EmployeeData> list;
public Employee(EmployeeData data)
{
list = new List<EmployeeData>();
list.Add(data);
}
public EmployeeData this[int index]
{
get { return list[index]; }
set { list[index] = value; }
}
public int Count
{
get { return list.Count; }
}
public void Add(EmployeeData data)
{
list.Add(data);
}
public IEnumerator<EmployeeData> GetEnumerator()
{
return list.GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator()
{
return list.GetEnumerator();
}
}
|
|
|
|
|
Indexers are unlikely to be a suitable technique. More information is needed.
|
|
|
|
|
ripples wrote: I am new to C# so pardon my mistakes. Your first mistake is trying to use an advanced technique before you are fully acquainted with the basics. In your main() method you are creating a new list e1 , every time the user selects option 1, and adding some information into it. You then break out of that case block and e1 goes out of scope and is disposed (i.e all information is thrown away). If the user selects option 2 you create a different new object e2 , and call the method to display its contents, but since you have not added anything into it there is no information to display. I would suggest going back to your notes and spending some time learning about creating and using objects. A good tutorial can be found in .NET Book Zero[^] by Charles Petzold.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
|
Note: this "experiment" was actually touched-off by Bob Janova's comment [^] on the recent thread on Tuples, "Tuples in Functions" [^], here, on this forum.
I'm not clear exactly why, but, that got me interested in what it would take to build a generic List of KeyValuePairs, where the 'Key would be a 'Type, and the 'Value an instance of that 'Type, and the 'Type for each KeyValuePair would be inferred from the 'Value.
The idea was that to to call a function that added items to the List<KeyValuePair> like this, passing in only the actual 'Value for each new KeyValuePair item:
AddToKVPList("tweet");
AddToKVPList(1.567893);
AddToKVPList(new TextBox()); I struggled to find a way to do this without using any "higher" .NET facilities, but could not achieve what I wanted: my final solution was
private List<KeyValuePair<Type, dynamic>> _listOkvp = new List<KeyValuePair<Type, dynamic>>();
private void AddToKVPList(object oIn)
{
workingType = oIn.GetType();
KeyValuePair<Type, dynamic> newKVP = new KeyValuePair<Type, dynamic>(workingType, oIn);
_listOkvp.Add(newKVP);
} If we execute the above code, and examine what _listOkvp is after the three calls to AddToKVPList in a 'Command' window in Visual Studio:
> ? _listOkvp
Count = 3
[0]: {[System.String, tweet]}
[1]: {[System.Double, 1.567893]}
[2]: {[System.Windows.Forms.TextBox, System.Windows.Forms.TextBox, Text: ]} Well, yes, that's what I was trying to get to: and, if you add this to iterate and print to the Console everything in the KeyValuePairList:
foreach(var kvp in _listOkvp)
{
Console.WriteLine(kvp.Value.GetType());
} You do get:
System.String
System.Double
System.Windows.Forms.TextBox So what's wrong ? Two things:
1. I believe I could have achieved this without using 'Dynamic, but I could not find a way to do that.
2. I cannot understand how I did transform the value of the (edit: 'Key)'Value, which was passed in as an 'object' parameter to the method 'AddToKVPList, to an actual instance of the 'Type of the passed in 'Value.
Which is worse: code you think should work, but does not, and you can't understand what's wrong, or: code that works, but you can't understand why ?
Appreciate your response: could this be done without 'dynamic ?
thanks, Bill
"One of the few good things about modern times: If you die horribly on television, you will not have died in vain. You will have entertained us." Kurt Vonnegut
modified 25-Aug-12 17:20pm.
|
|
|
|
|
1. As is often the case, you can replace dynamic with object and it will still work the same. The two are very similar.
2. You passed in the Value not the Key . The GetType method you called returns the true type of the object, not object :
object o = 1;
Console.WriteLine(o.GetType());
|
|
|
|
|
+5
Thanks, DaveyM69, I edited the OP to correct the mistake you identified: yes, I did pass in the 'Value for the KeyValuePair, not the 'Key !
I regret I did not keep back copies of my various failed attempts, so that I could examine them, now, since you enlightened me that object.GetType() will return the "true" 'Type !
best, Bill
"If you shoot at mimes, should you use a silencer ?" Stephen Wright
|
|
|
|
|
It can be done with a
List<KeyValuePair<Type, object>>
The example doesn't use the advantages of a dynamic (dynamic binding) over an object (static binding).
At this article http://msdn.microsoft.com/en-us/magazine/gg598922.aspx[^] the advantages are explained. Objects and dynamics are for a large part the same with one exception that the bindings aren't resolved until runtime. It is as if you tell the compiler "trust me, I know what I'm doing"
If the dymanic contains a System.Windows.Form.Textbox you could do this
dynamic something = new TextBox();
something.Text = "Hello dynamic world!";
You wouldn't be able to do this with an object. The programmer has to make sure that the something variable does have a Text property. Otherwise you would get a RuntimeBindingException.
dynamic something = "Change the value to a string";
something.Text = "Hello dynamic world!";
Another advantage of a dynamic would that you could call a method with a specific signature (because the real type of the dynamic is resolved at runtime).
public void DoSomething(string someValue) { Console.WriteLine("The value is a string: {0}", someValue); }
public void DoSomething(double someValue) {
Console.WriteLine("The value is a double: {0}", somevalue); }
public void CallTheRightDoSomething()
{
dynamic value = 0.5;
DoSomething(value);
value = "Now use it as a string";
DoSomehting(value);
}
With objects this would give an error. Due to the static binding nature of objects you would get a designtime error. var could solve this, but not as flexible as dynamic.
I guess using dynamic would only make sense if you really needs the dynamic binding behaviour. If you have functions that have different signatures to handle the values in your list (string, double, textbox), then it would be necessary to use dynamics. Otherwise you could use object.
|
|
|
|
|
+5
All your points about use of 'dynamic are very well articulated; I was aware of the late-binding aspect of dynamic, and have used it, for that purpose, in code (when I had to).
In this case, I just finally used 'dynamic because I couldn't get anything else to work
As I said, in my reponse to DaveyM69, "I regret I did not keep back copies of my various failed attempts, so that I could examine them, now."
The OP would have been more valuable, imho, if I had posted my last "failed" attempt, and then the attempt that "worked" for comparison.
Thanks for your time !
best, Bill
"If you shoot at mimes, should you use a silencer ?" Stephen Wright
|
|
|
|
|
I want to make a project this is related to hospital i only want how can we sen message from my network to the mobile.
abubakar
|
|
|
|
|
A little research[^] will get you going.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
You can locate an sms gateway and configure your application to send sms via this gateway,
|
|
|
|
|
and you've got to do some research into WHAT you're sending. In the US, if your application is sending PHI data to a phone over SMS, YOU will be in a ton of trouble. I hope your liability insurance is paid up.
|
|
|
|
|
Hi Friends I am Developing A form with datagridview Control in C# . In that i have added a DatagridviewDeleteButtonColumn .i wrote the Code in Datagridview _cellContentClick event for deleting rows.i got the output for this .But after that i have added a another button in form for adding data to the Datagirdview .Now My problem is data is adding to the database but after adding data if i try to delete any of the data means its not working (means no data gets Deleted). but after running the application if i am doing delete operation means the data gets deleted and if i am trying to delete the data again its not working.
My Coding is
<
Quote: Quote: public void del()
{ string css = ConfigurationManager.ConnectionStrings["cs"].ConnectionString;
c = new SqlConnection(css);
c.Open();
cd = new SqlCommand("delete from tblClientreg where CST_NO='" + dataGridView1.CurrentRow.Cells[6].Value.ToString() + "'", c);
cd.ExecuteNonQuery();
MessageBox.Show("CST_NO" + dataGridView1.CurrentRow.Cells[6].Value.ToString() + "Deleted Successfully", "Delete");
c.Close(); >
in datagridview
<Quote: if (e.ColumnIndex == 7)
{
del();
Ffill();
} >
|
|
|
|
|
I Want to binding a list of Frames to controls, how can i do that ?! or somethings like that,can you please help me out ?!
|
|
|
|
|
You are going to have to be way more specific than that.
Why is common sense not common?
Never argue with an idiot. They will drag you down to their level where they are an expert.
Sometimes it takes a lot of work to be lazy
Please stand in front of my pistol, smile and wait for the flash - JSOP 2012
|
|
|
|
|
What list of "Frames"? What's a "Frame"?
What list of "controls"? How are they related to the "Frames"??
Without this, you've got a lot of people scratching their heads wondering what you're talking about.
|
|
|
|
|
I have experience with VB with the very basics. I'm currently working on an app that allows me to see Japanese characters (Hiragana alphabet) and type with it using windows applications. I've been told that switching to C# is the best thing to do and I'm very overwhelmed since I only have knowledge with C# using the Console. If anyone has any information it would be greatly appreciated. Thanks in advance.
|
|
|
|
|
Diego Carrion wrote: If anyone has any information it would be greatly appreciated.
What specifically do you want to know? You've been told that switching to C# is the best thing to do for what?
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
I'm interested in designing applications in general. Right now I'm working on making my own visual Hiragana keyboard. I ran across this book: http://www.programmersheaven.com/ebooks/csharp_ebook.pdf[^].
I was told C# is the popular language to use because it mixes all of the other languages and makes life "easier". I'm completely new to this, all I've taken on programming are two very basic courses on C# (Console) and a object oriented programming on using VB.
|
|
|
|
|
Are you looking at doing programming professionally, or just as a hobby?
If professionally, then I would recommend you learn C# because you are likely to do more serious programming in C-type languages than in VB.
If you have specific questions about the Hiragana keyboard you're writing, I'm sure people here will be able to help when you get stuck.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|