|
|
What is the best way to populate a context menu with data from a DB when it is clicked on?
Basically I am trying to create a context menu from a notifyIcon and populate it with names & numbers when it is right clicked... I can get the data from the DB, I just need to know how to put this data into the menu... Any ideas or pointers?
Thanks in advance,
Phil
|
|
|
|
|
You can dynamically create the context menu when the click is performed. Also you can use one context menu and just clear the menu items and add new items at runtime. The code below is .NET 2 same logic different control in .NET 1.1
contextMenuStrip1.Items.Clear();
ToolStripItem ts = null;
for(int i=0;i<5;i++){
ts = contextMenuStrip1.Items.Add(i.ToString());
}
contextMenuStrip1.Show();
A man said to the universe:
"Sir I exist!"
"However," replied the Universe, "The fact has not created in me A sense of obligation."
-- Stephen Crane
|
|
|
|
|
We can create context menu in this way but also we need to handle events for these context menus. To do so we can create a common event for all menu items and then based on the context name respective code can be executed.
Impossible itself says I M Possible.
|
|
|
|
|
duh
private void button1_Click(object sender, EventArgs e) {
contextMenuStrip1.Items.Clear();
ToolStripItem ts = null;
for(int i=0;i<5;i++){
ts = contextMenuStrip1.Items.Add(i.ToString());
ts.Click += new EventHandler(ts_Click);
ts.Tag = [PUT SOMETHING HERE TO ID IT]
}
contextMenuStrip1.Show();
}
private void ts_Click(object sender, EventArgs e){
...
}
A man said to the universe:
"Sir I exist!"
"However," replied the Universe, "The fact has not created in me A sense of obligation."
-- Stephen Crane
|
|
|
|
|
All you have to do is bind your events at the time you create each context menu item. You would basically be doing in abstract code, what the designer does with hard coded code.
foreach ( string element in myListofThings )
{
ToolStripMenuItem menu = new ToolStripMenuItem();
menu.Name = element.ToLower();
menu.Text = element;
menu.Click+=new SystemEventHandler(HandleContextClick);
myContextMenu.Add( menu );
foreach ( string subElement in SubElementList )
{
ToolStripMenuItem submenu = new ToolStripMenuItem();
blah blah blah
submenu.Click+=new SystemEventHandler(HandleSubContextClick);
}
}
|
|
|
|
|
Hello,
It's the first time to use Microsoft.Reporting.WinForms.ReportViewer , and i need some one expert to help me...
I've created a win form using C# and added a ReportViewer control then i've designed a new report and set the LocalReport.DataSources, LocalReport.ReportEmbeddedResource and LocalReport.ReportPath.
My problem is : after opening this report in run time successfully, i want to receive the DoubleClick event that occurred when double clicking on the FieldObject (TextBox), but this not happen when !
if you have an idea or sample to help me, plz reply or send to me at bahaa_sa5@hotmail.com
thanks alot
bahaa
|
|
|
|
|
hi all,
here i have two windows of same instance open.
when i execute some process in first window and the process is busy, i should be able to work on the second window. i.e asynchronous programming(windows forms .net 2.0).
but iam not able to do it .
Can any one help me out............plz.
|
|
|
|
|
|
If you really need two separate windows for doing processes, you may want to also consider implementing both windows inside of an MDIParent, in addition to using a BackgroundWorker thread.
|
|
|
|
|
i have wold file with fname , lname & status
and i have C# app that i will fill all this data (fname , lname & status )
and send this data as parameter to MSWord and print it
u can see MSWord file in
http://www.shoppinp.com/test.doc
and the win app in this file
http://www.shoppinp.com/test.gif
|
|
|
|
|
if i cant do this what the best way to do this ..........
Palestine
|
|
|
|
|
i guss i had similar question before ,so search for my question "how to print part of the document" my member name khalid sabtan
you also have to do the following
1- make a textbox at the location you want to print on(inside your document)
2-bring the cursor inside that textbox and make a book mark by msword and give it a name such as mybookmark1
3-inside your c# program send your string to that bookmark, it should land on that textbox
4- to undestand how to send 2 the book mark
look at this
Object name = mybookmark1;
Word Range rng = oDataDoc.Bookmarks.get_Item(ref name).Range;
rng.Text = "Hellow TAREQ F ABUZUHRI"
modified 3-Jul-12 18:19pm.
|
|
|
|
|
Hey guys.
I just started a new job which requires C# skills so I'm trying to get myself up to speed and while I've been able to understand most of the stuff so far, one thing I don't understand is what is the purpose of the ":" and everything after it when creating a class?
For example, what does the ":" mean in the following line and what is the purpose for "ExcelReport, IReport":
------------------------------------------------
public class SampleClass: ExcelReport, IReport
-------------------------------------------------
This code is basically from one of their applications. It writes a report to an excel file.
Oh, also if it's not too much trouble, can anyone explain what ":base()" is used for? For example:
---------------------------------------
public SampleClass(FileInfo fileName)
: base(fileName)
---------------------------------------
Thanks again guys.
-Goalie35
-- modified at 9:02 Thursday 10th August, 2006
|
|
|
|
|
inheritance
SampleClass is inherited from ExcelReport.
:Base(fileName) calls the constructor of the base class.
Hope this helps.
I've found a living worth working for, but I haven't found work worth living for.
<marquee>
|
|
|
|
|
The : in the class declaration indicates that your class will inherite from some other class. In the example you gave:
public class SampleClass: ExcelReport, IReport
SampleClass inherits from the class ExcelReport, and the interface IReport.
Roy.
|
|
|
|
|
Other have provided the correct answer but I must recommend purchasing a book on C# if you are at this level of newness. Many of these sort of questions will be covered ad naseum in the first few chapters catapulting you ahead of your peers (assuming you asked them and they didn't know either)
Not only will you have the what but you will have the why.
A man said to the universe:
"Sir I exist!"
"However," replied the Universe, "The fact has not created in me A sense of obligation."
-- Stephen Crane
|
|
|
|
|
I would agree with Ennis on getting yourself a book. I would suggest that you may want to splurge on two books:
Get a small book to get a quick overview of C#.
Then a detailed one that goes into everything there is to know.
Once you feel comfortable, get yourself the Design Patterns in C# book as this will become your development bible.
When you do inheritance you can inherit an interface ( public interface ISomething ) and you can inherit an abstract class or inheritable class ( public abstract class Something or public class Something ).
You can only inherit a single object and that must be the first name in your list after ':'. All others must be interfaces. This is called single inheritance. The benefits of inheritance is that you automatically gain the methods the original class already had written and tested. (which means you may not have to)
If you want to change or add behavior you then override a method and add your own code. Calling base.Method() either in the method signature or in your method is how you execute the code your program is hiding from users of your program. So if you see something like this:
public override bool MyOveridableMethod(string parm, bool state)
:base(parm,state)
{
}
then the developer wants the base method to execute first before executing his own code. If you see code like this:
public override bool MyOveridableMethod(string parm, bool state)
{
....
}
then the developer wants to control when (or if) the underlying code is executed.
If this description totally loses you, then it is further proof you really need to do some reading. But you will absorb it and in a few months it will all start to sound like common English.
-- modified at 16:33 Thursday 10th August, 2006
|
|
|
|
|
Im going to have to ask for both n's in Ennis for obvious reasons. The two are pronounced entirely different and misspelling lead to humourous consequences.
A man said to the universe:
"Sir I exist!"
"However," replied the Universe, "The fact has not created in me A sense of obligation."
-- Stephen Crane
|
|
|
|
|
So sorry. It is modified so no one will read it with a long E.
|
|
|
|
|
hi friends, i have made a client/server application using socket connection.
now i have a problem like how to transfer the data between client and server.
can anybody help me?
|
|
|
|
|
hi,
Try this code
<code>
//Server
Socket server = new Socket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp);
server.Bind(new IPEndPoint(IPAddress.Any,20000));
m_tcpListener.Listen(50);
Socket client = server.Accept(); // wait for a client to connect
string message = "Testing 1,2,3";
client.Send(Encoding.ASCII.GetBytes(message));
client.Shutdown(SocketShutdown.Both);
client.Close();
server.Close();
//Client
Socket client = new Socket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp);
client.Connect(new IPEndPoint(Dns.Resolve("127.0.0.1").AddressList[0],1000));
byte []buffer = new byte[1024];
int read = client.Receive(buffer);
Console.WriteLine(Encoding.ASCII.GetString(buffer,0,read));
</code>
It's just a simple example in which a server waits for a client to connect then sends to the client a message, and the client prints the received message. Hope it's a start for you.
Do your best to be the best
|
|
|
|
|
hi karkster
thankyou for your reply. I am doing a project on media player. i want to transfer the music files between the client and server. can you suggest me how to transfer the playlist from client to server.
Thankyou.
|
|
|
|
|
Hi,
To send a file to the client you just need to do this:
<br />
FileStream fstream = File.Open(filename,FileMode.Open);<br />
byte []buffer = new byte[fstream.Length];<br />
fstream.Read(buffer,0,buffer.Length);<br />
fstream.Close();<br />
Use the buffer instead of the Encoding.ASCII.GetBytes(). The sockets send and receive byte arrays.
Do your best to be the best
|
|
|
|
|
hi all,i need to search the word present in the word document (this word document is present in the aplication domain).Is it possible...how to do this.....
ayyp
|
|
|
|