|
Basically, you need to handle the MouseDown event on the listbox and select the item you clicked.
private void listBox1_MouseDown(object sender, MouseEventArgs e)
{
ListBox listBox = sender as ListBox;
if (e.Button == MouseButtons.Right)
{
int index = listBox.IndexFromPoint(e.X, e.Y);
if (index >= 0 && index < listBox.Items.Count)
{
listBox.SelectedIndex = index;
}
listBox.Refresh();
}
}
In your event handler for the the context menu item, you will need to test if there are any selected items and do the appropriate action. Something like this:
private void deleteToolStripMenuItem_Click(object sender, EventArgs e)
{
if (listBox1.SelectedItems.Count > 0)
{
MessageBox.Show(listBox1.SelectedItems[0].ToString());
}
else
{
MessageBox.Show("You didn't select an item!");
}
}
If you really want to, you would actually enable/disable context menu options in your MouseDown event handler based on an item being selected or the user right clicking in "white space".
-----------------------------
In just two days, tomorrow will be yesterday.
|
|
|
|
|
Thank you both (though one was more impudent than the other .
I've browsed the documentation and googled the question without finding an answer. Guess I simply failed to spot that particular member. RTFM is simple enough, one should think.
But thanks again.
|
|
|
|
|
Hey, this is my problem: i select the last line after i added the new text, i change the color of the line, but then all the lines before becomes the first color inserted and not the color i added them before.
what's the problem and how can i fix it?
this is the code where i add the text in:
private void rtbAddText(String NewText, Color NewColor)
{
NewText += Environment.NewLine;
if (NewColor == null)
this.rtbConsole.Text = NewText;
else
{
int OldLength = rtbConsole.Text.Length;
this.rtbConsole.Text += NewText;
this.rtbConsole.Select(OldLength, NewText.Length);
this.rtbConsole.SelectionColor = NewColor;
}
}
Thanks... NaNg.
|
|
|
|
|
rather than using
this.rtbConsole.Text += NewText; you should use
this.rtbConsole.AppendText(NewText);
HTH
|
|
|
|
|
Thanks.... was looking for Add() function... (at start) :P
|
|
|
|
|
Hi,
Is it possible to load up a GridView where all rows are in edit mode?
Thanks
|
|
|
|
|
Is this an ASP.NET question?
led mike
|
|
|
|
|
|
I have never been able to figure this oneout, or find anything that reliably worked, either.
i am trying to develope an app that uses a richtextbox for input, and has all the options that wordpad does. Now, i realise i may not be able to pull off each and every trick, but there is one in particular that is driving me crazy. in wirdpad, say I have this sentance:
Bold and Italic are font styles.
Now, something i can do very easily is switch individual selections back and forth between one font style and another, so this would be easy:
Bold and Italic are font styles.
the problem is, if i want to do this:
Bold and Italic are font styles.
i get one or the other, basically whichever i selected last. here is the code i am using. rtb is the RichTextBox:
private void btnBold_Click(object sender, EventArgs e)<br />
{<br />
if (rtb.SelectionFont.Bold)<br />
rtb.SelectionFont = new Font(rtb.SelectionFont.FontFamily, rtb.SelectionFont.Size, FontStyle.Regular);<br />
else<br />
rtb.SelectionFont = new Font(rtb.SelectionFont.FontFamily, rtb.SelectionFont.Size, FontStyle.Bold);<br />
rtb.Select();<br />
}<br />
<br />
private void btnItal_Click(object sender, EventArgs e)<br />
{<br />
if (rtb.SelectionFont.Italic)<br />
rtb.SelectionFont = new Font(rtb.SelectionFont.FontFamily, rtb.SelectionFont.Size, FontStyle.Regular);<br />
else<br />
rtb.SelectionFont = new Font(rtb.SelectionFont.FontFamily, rtb.SelectionFont.Size, FontStyle.Italic);<br />
rtb.Select();<br />
}
I am using C# express and the 2.0 framework. Any ideas?
______________________
Mr Griffin, eleventy billion is not a number...
|
|
|
|
|
in each one u do not check if it's the other one.
if it is it resets the other one....
think about it.
|
|
|
|
|
Granted, that is true, but even if I just set it to italic or bold, like this:
private void btnBold_Click(object sender, EventArgs e)<br />
{<br />
rtb.SelectionFont = new Font(rtb.SelectionFont.FontFamily, rtb.SelectionFont.Size, FontStyle.Bold);<br />
rtb.Select();<br />
}<br />
<br />
private void btnItal_Click(object sender, EventArgs e)<br />
{<br />
rtb.SelectionFont = new Font(rtb.SelectionFont.FontFamily, rtb.SelectionFont.Size, FontStyle.Italic);<br />
rtb.Select();<br />
}
whatever the new fontstyle is, it overrides the existing one. So for example, i have this:
Short sentance
and i highlight like this:
Short se ntance
then try setting it to iatlics, rather than getting this:
Short sentance
i get this:
Short sentance
______________________
Mr Griffin, eleventy billion is not a number...
|
|
|
|
|
Try something like this -->
this.richTextBox1.Text = "This is a test";
this.richTextBox1.SelectionStart = 0;
this.richTextBox1.SelectionLength = 7;
System.Drawing.Font currentFont = richTextBox1.SelectionFont;
System.Drawing.FontStyle newFontStyle;
newFontStyle = FontStyle.Bold;
richTextBox1.SelectionFont = new System.Drawing.Font(currentFont.FontFamily, currentFont.Size, newFontStyle);
currentFont = richTextBox1.SelectionFont;
this.richTextBox1.SelectionStart = 5;
this.richTextBox1.SelectionLength = 3;
newFontStyle = FontStyle.Italic | FontStyle.Bold;
richTextBox1.SelectionFont = new System.Drawing.Font(currentFont.FontFamily, currentFont.Size, newFontStyle);
It's only when you look at an ant through a magnifying glass on a sunny day that you realise how often they burst into flames.
|
|
|
|
|
Awesome! That certainly got me going in the right direction. Its almost emberassing how long i have tried to get this working....
______________________
Mr Griffin, eleventy billion is not a number...
|
|
|
|
|
Glad to help.
It's only when you look at an ant through a magnifying glass on a sunny day that you realise how often they burst into flames.
|
|
|
|
|
i have a dataview it has several rows
how can i pass thes rows to a datatable?
thanks for help
MD_NADA
|
|
|
|
|
Isn't your DataView based on a table already?
|
|
|
|
|
my dataview is aleady based on dataset but i filter the dataset by dataview
and i want to get the rows in the dataview in datatable
thanks for your help
MD_NADA
|
|
|
|
|
What do you mean when you say filter? Also, does the datagrid contain child rows? Why dont you just use your dataset if these rows are already there?
|
|
|
|
|
My application pulls data from a MySQL database and saves it as CSV file.
I have to localize this. the main requirement is that date and number format should be localized while making the CSV file.
for ex in German, the delimiter should be ";" instead of " ," . and numbers should have , in place of decimal(1.23 should be 1, 23) and also the date should be in correct format.
now the data I am pulling could be of any type, string, single, double, how can I know the type of pulled data, and format it for the installed UI culture before saving it to the CSV file.
I know that I can find out the type of the column pulled, and use that, is there a better an efficient way ?
Any ideas ?
Thanks,
Arti
|
|
|
|
|
IMHO the most simple solution will be to write data in binary mode. After that data will be automatically reformatted according to local settings of the target computer while reading.
|
|
|
|
|
I am having a problem I am not sure why is hapening. In the following code, if I put the line with the Clone() method before the this.datagridSplit.Panel2.Controls.Add(dataGrid); it works well but I get the error No parameterless constructor defined for this object in a MissingMethodException. My guess is that is because the object is occupied on another thread but I am not sure. Note that when the dataGrid is added to a control I fire another event that modifies the bound table of the datagrid. What a day!
public void SetFinder(ref ComplexObject finderObject) //Type ComplexObject is a typed dataset
{
finderObject.Read();
complexObject = finderObject;
dataGrid = finderObject.FinderDatagrid;
dataGrid.ColumnHeadersVisible = false;
this.datagridSplit.Panel2.Controls.Add(dataGrid);
emptyDataSet = finderObject.Clone();
emptyDataSet.EnforceConstraints = false;
emptyDataSet.Tables[0].Rows.Add(null, null);
emptyDataSet.AcceptChanges();
emptyDataGrid.DataSource = emptyDataSet.Tables[0];
emptyDataGrid.AllowUserToAddRows = false;
emptyDataGrid.Dock = DockStyle.Fill;
emptyDataGrid.RowHeadersVisible = false;
this.datagridSplit.Panel1.Controls.Add(emptyDataGrid);
this.emptyDataGrid.CellValueChanged += new DataGridViewCellEventHandler(emptyDataGrid_CellValueChanged);
this.emptyDataGrid.CellLeave += new DataGridViewCellEventHandler(emptyDataGrid_CellLeave);
}
|
|
|
|
|
Hi
please help me in this:
I have loaded xml document using following DOM class:
<br />
<br />
XmlDocument xDoc = new XmlDocument();<br />
<br />
xDoc.Load("check.xml");<br />
<br />
Now how can i view this xml file similar to internet explorer display?
Either i should draw Rich Text Box or drop WebControl on my the form? I have added WebControl in toolbox but it is disable there.
please help me.
Thank you.
|
|
|
|
|
You mean the control is disabled in your toolbox ?
Cross my heart, smack me dead...stick a lobster on my head.
|
|
|
|
|
Yes here in mine toolbox
|
|
|
|
|
Is there a way to create a program that will constantly update what programs the current user is using? I tried using GetCurrentProcess, but it gets my window, and not the currently activated window. What I do is, I have a thread that will keep watching the processes, calling the GetCurrentProcess function to constantly update. This thread only activates when the form is "deactivated". The problem is that I just keep getting my app, and not the other processes.
|
|
|
|