|
|
I am using the code shown below to allow the user to click on a listview item and display a file associated with the item clicked.
However, It is failing at the indicated line because users are still holding down the mouse button while changing the listview selection via the keyboard arrow keys.
How can I prevent this from happening please?
void diaryListView_MouseUp(object sender, MouseEventArgs e)
{
int selectedSubItem =
this.GetSubItem(this.diaryListView, new Point(e.X, e.Y));
if (selectedSubItem != -1)
{
ListViewItem lvItem = diaryListView.SelectedItems[0]; *** FAILS HERE ***
var file = lvItem.SubItems[14].Text.ToString();
if (selectedSubItem == 0 & lvItem.SubItems[14].Text.ToString().Length > 0)
{
viewFile(file);
}
}
}
public struct RECT
{
public int Left;
public int Top;
public int Right;
public int Bottom;
}
[DllImport("user32.dll")]
private extern static int SendMessage(
IntPtr hWnd, int wMsg, int wParam, ref RECT lParam);
public int GetSubItem(ListView lv, Point pt)
{
const int LVM_FIRST = 0X1000;
const int LVM_GETSUBITEMRECT = LVM_FIRST + 56;
const int LVIR_BOUNDS = 0;
ListViewItem.ListViewSubItem subItem = null;
int subItemIDX = -1;
RECT lviRect;
ListViewItem lvi = lv.GetItemAt(pt.X, pt.Y);
if (lvi == null && lv.SelectedItems.Count > 0)
lvi = lv.SelectedItems[0];
if (lvi != null)
{
int sendMessageVal = 0;
for (int i = 1; i < lvi.SubItems.Count; i++) {
subItem = lvi.SubItems[i];
lviRect = new RECT();
lviRect.Top = i;
lviRect.Left = LVIR_BOUNDS;
sendMessageVal =
SendMessage(lv.Handle,
LVM_GETSUBITEMRECT,
lvi.Index,
ref lviRect);
if (pt.X < lviRect.Left)
{
subItem = lvi.SubItems[0];
subItemIDX = 0;
break;
}
else if (pt.X >= lviRect.Left & pt.X <= lviRect.Right) {
subItemIDX = i;
break;
}
else
subItem = null;
}
}
if (subItem == null || lvi == null)
subItemIDX = -1;
return subItemIDX;
}</remarks></returns></summary>
modified on Friday, February 20, 2009 8:27 AM
|
|
|
|
|
kanchoette wrote: It is failing
isn't very descriptive; can you describe how it's failing?
Without that here are some comments anyway:
* why subscribe to the mouse up handler for this? like you said that will completely ignore the user hitting up and down on the keyboard. subscribing to diaryListView.SelectedIndexChanged would notify you any time the selection changes regardless of how the user made it happen.
* GetSubItem ? Why bother with this function? you're ignoring the index that was actually clicked and using zero instead, so why not just check if (diaryListView.SelectedItems.Count > 0) instead of if (selectedSubItem != -1) ?
* var file = lvItem.SubItems[14].Text.ToString(); -- what is this? Text is a string, then ToString() converts it to another string even though it already is one and then it's stored in a var even though you've jumped through hoops to ensure it's a string. Why? and why is it repeated in the conditional on the next line?
|
|
|
|
|
I fixed it by adding the top if statement
if (diaryListView.SelectedItems.Count > 0)
{
ListViewItem lvItem = diaryListView.SelectedItems[0];
var file = lvItem.SubItems[14].Text.ToString();
if (selectedSubItem == 0 & lvItem.SubItems[14].Text.ToString().Length > 0)
{
viewFile(file);
}
}
|
|
|
|
|
Hi, how can i create or delete a table in MsAccess using c# and Microsoft.Jet.OLEDB.4.0?
ty very much
Alessio
|
|
|
|
|
What are you having problems with? You need to call a command that executes a 'create' or 'drop' statement on the access database - have you written any code to do this?
It definitely isn't definatley
|
|
|
|
|
Bad Moon_Stick! Didn't you know that you've entered into A Contract with Legion the moment you helped someone? You are now required to write the homework for anyone who asks.
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|
|
Ah crap - I wish I'd know that earlier!!
Sometimes it almost seems like it'd be better if I didn't try and help at all - it really does annoy me!!
It definitely isn't definatley
|
|
|
|
|
DataTable tabella = new DataTable("letturair");
DataColumn colonna;
DataRow righe;
OleDbCommand comando;
OleDbDataAdapter adattatore;
colonna = new DataColumn();
colonna.DataType = System.Type.GetType("System.String");
colonna.ColumnName = "CODICE";
tabella.Columns.Add(colonna);
string nomeColonna;
for (int i=1; i<=Convert.ToInt32(tbNumeroQuesiti.Text); i++)
{
nomeColonna="R"+Convert.ToString(i);
tabella.Columns.Add(nomeColonna, typeof(String));
}
....and now? how can i create my table in a Access document?
ty very much
|
|
|
|
|
using System.Data.OleDb;
then you will need to create instances of OleDbConnection and OleDbCommand
pass your database connection string to OleDbConnection then open the connection.
create an SQL Query[^] as a string and pass that, along with the OleDbConnection, to the OleDbCommand
then execute the OleDbCommand as required
p.s. dont forget to use command parameters if you have any UI values
If only MySelf.Visible was more than just a getter...
A person can produce over 5 times there own body weight in excrement each year... please re-read your questions before posting
|
|
|
|
|
When I asked if you had written any code, I meant, have you written any code that will create or delete a table?
If you try and write code (looking at google or documentation will be useful here) and have difficulty with something, I'll try and give some useful advice but I'm not going to write all the code for you.
Go and make some kind of an effort to solve the problem before you start asking questions - I won't offer any help until you've done that.
It definitely isn't definatley
|
|
|
|
|
Hi,
I'm using a DataGridView to display a number of files. I would like to use a ContextMenuStrip to give the user access to some basic functionality for manipulating the files. I have managed to do so, the context menu works and I have determined that the correct cells are being affected by the actions on the context menu. How ever, when I left click a file in my gridview the file is selected and thus highlighted. I would like this to happen when I right click the file to bring up the context menu too.
This snippet does the work if I disable the context menu:
private void viewFiles_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
viewSessions.Rows[e.RowIndex].Selected = true;
}
}
I guess that what I want is to execute this code before showing the context menu, right? Any ideas?
|
|
|
|
|
instead of attaching the context menu to the dataGridView leave it unattached
Then when you set the .Selected = true; in your above event handler add the follwing line
contextMenu1.Show(Cursor.Position);
If only MySelf.Visible was more than just a getter...
A person can produce over 5 times there own body weight in excrement each year... please re-read your questions before posting
|
|
|
|
|
Hi Frnds
I want to implement a application in which i can open any file, image or video through mobile from remote place
Plz help me out It's urgent.......
Thanks in advance.......
modified on Friday, February 20, 2009 8:27 AM
|
|
|
|
|
Took me almost half an hour before I realised that it's not meant seriously! Good one!
I are troll
|
|
|
|
|
If u don't know to implement don't post ur comment.
|
|
|
|
|
If you don't know how to read
- f_off!
If you refuse to spell
- f_off and die!
If you won't make an effort
- f_off and die you m_f_er!
If you want others to do your homework
- f_off and die you m_f_ing p_drinking a_sucker!
Kapeesh?
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|
|
williamnw wrote: If you refuse to spell
- f_off and die!
If only MySelf.Visible was more than just a getter...
A person can produce over 5 times there own body weight in excrement each year... please re-read your questions before posting
|
|
|
|
|
|
Occassionally. Just occassionally. I get 'vexed' and I need to vent. It's a bit like those vile felines scratching at the nearest piece of tailoring there bi-cellular brains encounter.
You goive a guy a hint. He doesn't even take the hint and tries to snarl his yellow teeth at you. You know what I say? "Bring 'em on! And there damned cats!"
[btw thank you for the 5, have one back.]
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|
|
Hey hey now! What's all this? Are you trying to mimic my attitude?
|
|
|
|
|
Hi, Welcome to being scorned. You are being laughed at for the following:
1. Using all bold text
2. Using 1337 txt spek.
3. Asking for code.
4. Being stupid
Please correct all of the above and ask again, make sure to look at point 4. Google can help you with that.
|
|
|
|
|
You should be able to make use of the following framework:
using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.IO;
namespace NeedsCode
{
class Program
{
static void Main(string[] args)
{
throw new NotImplementedException("The program code needs to be implemented.");
}
}
}
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|
|
well first you might want to consider how you plan to connect to the mobile.... then who knows
Oh, if you do somehow make this application, dont forget how i helped. the source code as a reward should be fine
If you reply to this 'aashish patidar' then i will accept as a written agreement fro my reward
If only MySelf.Visible was more than just a getter...
A person can produce over 5 times there own body weight in excrement each year... please re-read your questions before posting
|
|
|
|
|
OK. First you need to port every file, image, and video reader application to your mobile. Then you need to send the files to it.
Today's lesson is brought to you by the word "niggardly". Remember kids, don't attribute to racism what can be explained by Scandinavian language roots.
-- Robert Royall
|
|
|
|