Click here to Skip to main content
15,905,325 members
Home / Discussions / C#
   

C#

 
GeneralRe: Splitting strings Pin
kanchoette20-Feb-09 4:30
kanchoette20-Feb-09 4:30 
QuestionC# client server communication [modified] Pin
mrithula820-Feb-09 4:19
mrithula820-Feb-09 4:19 
AnswerRe: C# client server communication Pin
Rob Philpott20-Feb-09 4:42
Rob Philpott20-Feb-09 4:42 
GeneralRe: C# client server communication Pin
Mel Feik20-Feb-09 5:54
Mel Feik20-Feb-09 5:54 
QuestionPass a dynamic collection from c# to c++ dll Pin
johnnycastle20-Feb-09 2:46
johnnycastle20-Feb-09 2:46 
Questionpc oscilloscope usb based Pin
wepce20-Feb-09 2:33
wepce20-Feb-09 2:33 
AnswerRe: pc oscilloscope usb based Pin
kanchoette20-Feb-09 2:46
kanchoette20-Feb-09 2:46 
QuestionUser holding down mouse while changing listview selection via keyboard problem [modified] Pin
kanchoette20-Feb-09 2:14
kanchoette20-Feb-09 2:14 
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);
	
	        /// <summary>
	        /// Return -1 if invalid subitem clicked otherwise return index
	        /// of clicked subitem (zero based)
	        ///
	        ///
	        ///
	        /// <returns>int
	        /// <remarks>
	        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

AnswerRe: User holding down mouse while changing listview selection via keyboard problem [modified] Pin
Jimmanuel20-Feb-09 3:59
Jimmanuel20-Feb-09 3:59 
GeneralRe: User holding down mouse while changing listview selection via keyboard problem Pin
kanchoette20-Feb-09 4:18
kanchoette20-Feb-09 4:18 
QuestionNew Table Pin
Alessio Granzotto20-Feb-09 1:22
Alessio Granzotto20-Feb-09 1:22 
AnswerRe: New Table Pin
moon_stick20-Feb-09 1:32
moon_stick20-Feb-09 1:32 
GeneralRe: New Table Pin
Nagy Vilmos20-Feb-09 1:46
professionalNagy Vilmos20-Feb-09 1:46 
GeneralRe: New Table Pin
moon_stick20-Feb-09 2:06
moon_stick20-Feb-09 2:06 
GeneralRe: New Table Pin
Alessio Granzotto20-Feb-09 1:58
Alessio Granzotto20-Feb-09 1:58 
GeneralRe: New Table Pin
musefan20-Feb-09 2:05
musefan20-Feb-09 2:05 
GeneralRe: New Table Pin
moon_stick20-Feb-09 2:05
moon_stick20-Feb-09 2:05 
QuestionDataGridView selection problem Pin
pedersen-roxen20-Feb-09 1:20
pedersen-roxen20-Feb-09 1:20 
AnswerRe: DataGridView selection problem Pin
musefan20-Feb-09 2:44
musefan20-Feb-09 2:44 
QuestionHow can we open any .doc/image/..... file on PC through remote place mobile [modified] Pin
aashish patidar20-Feb-09 1:18
aashish patidar20-Feb-09 1:18 
JokeRe: How can we open any .doc/image/..... file on PC through remote place mobile Pin
Eddy Vluggen20-Feb-09 2:15
professionalEddy Vluggen20-Feb-09 2:15 
GeneralRe: How can we open any .doc/image/..... file on PC through remote place mobile Pin
aashish patidar20-Feb-09 2:25
aashish patidar20-Feb-09 2:25 
RantRe: How can we open any .doc/image/..... file on PC through remote place mobile PinPopular
Nagy Vilmos20-Feb-09 2:37
professionalNagy Vilmos20-Feb-09 2:37 
JokeRe: How can we open any .doc/image/..... file on PC through remote place mobile Pin
musefan20-Feb-09 2:54
musefan20-Feb-09 2:54 
GeneralRe: How can we open any .doc/image/..... file on PC through remote place mobile Pin
EliottA20-Feb-09 2:54
EliottA20-Feb-09 2:54 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.