Click here to Skip to main content
15,920,602 members
Home / Discussions / C#
   

C#

 
GeneralRe: Controlling Panels via RadioButtons Pin
Heath Stewart13-Feb-04 5:32
protectorHeath Stewart13-Feb-04 5:32 
Generaldocked controls snapping to grid in compiled app Pin
Nathan Ridley13-Feb-04 4:16
Nathan Ridley13-Feb-04 4:16 
GeneralRe: docked controls snapping to grid in compiled app Pin
leppie13-Feb-04 19:14
leppie13-Feb-04 19:14 
GeneralRe: docked controls snapping to grid in compiled app Pin
Nathan Ridley14-Feb-04 0:06
Nathan Ridley14-Feb-04 0:06 
AnswerRe: listView - is there a bug? Pin
thomasa13-Feb-04 1:54
thomasa13-Feb-04 1:54 
GeneralRe: listView - is there a bug? Pin
Andy H13-Feb-04 3:16
Andy H13-Feb-04 3:16 
GeneralRe: listView - is there a bug? Pin
Heath Stewart13-Feb-04 3:50
protectorHeath Stewart13-Feb-04 3:50 
GeneralRe: listView - is there a bug? Pin
Andy H13-Feb-04 9:55
Andy H13-Feb-04 9:55 
I drop files onto the listView control, and the fullpath to each file is stored into a member ArrayList, the listView shows the file names and their associated icon which is extracted at runtime and placed into an imageList. The index's for the listView, ArrayList and imageList are all kept in sync.

Here's my code, first the InitializeComponent part for the listView:

this.listView1.AllowDrop = true;<br />
this.listView1.CheckBoxes = true;<br />
this.listView1.LabelWrap = false;<br />
this.listView1.LargeImageList = this.imageList1;<br />
this.listView1.Location = new System.Drawing.Point(24, 24);<br />
this.listView1.Name = "listView1";<br />
this.listView1.Size = new System.Drawing.Size(224, 224);<br />
this.listView1.SmallImageList = this.imageList1;<br />
this.listView1.TabIndex = 2;<br />
this.listView1.View = System.Windows.Forms.View.SmallIcon;<br />
this.listView1.DragDrop += new System.Windows.Forms.DragEventHandler(this.listView1_DragDrop);<br />
this.listView1.DragEnter += new System.Windows.Forms.DragEventHandler(this.listView1_DragEnter);


then the two events for Drag 'n' Drop:

private void listView1_DragEnter(object sender, System.Windows.Forms.DragEventArgs e)<br />
		{<br />
			if(e.Data.GetDataPresent(DataFormats.FileDrop))<br />
				e.Effect = DragDropEffects.All;<br />
			else<br />
				e.Effect = DragDropEffects.None;<br />
		}<br />
<br />
		private void listView1_DragDrop(object sender, System.Windows.Forms.DragEventArgs e)<br />
		{<br />
			string[] s = (string[]) e.Data.GetData(DataFormats.FileDrop, false);<br />
			for(int i = 0; i < s.Length; i++)<br />
			{<br />
				/* Check that s[i] doesn't exist in listView1 before we add it, <br />
				   to prevent duplicates. */<br />
				if (!m_szFullFilePaths.Contains (s[i]))<br />
				{<br />
					/* s[i] hasn't been added to add to our array of full paths<br />
					   and also the listView1.	 */<br />
					int j = listView1.Items.Count;<br />
					m_szFullFilePaths.Capacity = j+1;<br />
					m_szFullFilePaths.Add (s[i]);<br />
					// We only want to display the file and not the full path:<br />
					Regex reg = new Regex (@"\\");<br />
					string[] p = reg.Split (s[i]);<br />
					listView1.Items.Add(p[p.Length - 1]);<br />
					<br />
					Icon ico = ExtractIcon.GetIcon (s[i],true, false);<br />
					imageList1.Images.Add (ico);<br />
					listView1.Items[j].ImageIndex = j;<br />
				}<br />
			}<br />
		}


And finally the button click event for the "Clear" button, so that a fresh selection of files can be made:

private void btnClearLV_Click(object sender, System.EventArgs e)<br />
		{<br />
			// Clear the listView member array, and imageList1.<br />
			listView1.Items.Clear ();<br />
			m_szFullFilePaths.Clear ();<br />
			m_szFullFilePaths.Capacity = 0;<br />
			imageList1.Images.Clear ();<br />
		}


Heres hoping someone can spot the problem, cause I can't.
GeneralRe: listView - is there a bug? Pin
Heath Stewart13-Feb-04 12:07
protectorHeath Stewart13-Feb-04 12:07 
GeneralRe: listView - is there a bug? Pin
Andy H13-Feb-04 23:37
Andy H13-Feb-04 23:37 
QuestionlistView - is there a bug? Pin
Andy H12-Feb-04 23:48
Andy H12-Feb-04 23:48 
GeneralConvert String[] to System.Array Pin
RickardB12-Feb-04 20:11
RickardB12-Feb-04 20:11 
GeneralRe: Convert String[] to System.Array Pin
Mazdak12-Feb-04 20:38
Mazdak12-Feb-04 20:38 
GeneralRe: Convert String[] to System.Array Pin
Ungi.1-Mar-04 20:54
Ungi.1-Mar-04 20:54 
GeneralOpen DAO Recordset Pin
Daminda12-Feb-04 19:58
Daminda12-Feb-04 19:58 
GeneralRe: Open DAO Recordset Pin
Heath Stewart13-Feb-04 3:45
protectorHeath Stewart13-Feb-04 3:45 
GeneralHelp me finish this solution Pin
Anonymous12-Feb-04 19:30
Anonymous12-Feb-04 19:30 
GeneralRe: Help me finish this solution Pin
Heath Stewart13-Feb-04 3:42
protectorHeath Stewart13-Feb-04 3:42 
GeneralUsing Interfaces Practically Pin
Anonymous12-Feb-04 19:20
Anonymous12-Feb-04 19:20 
GeneralRe: Using Interfaces Practically Pin
Mazdak12-Feb-04 19:27
Mazdak12-Feb-04 19:27 
GeneralRe: Using Interfaces Practically Pin
Anonymous13-Feb-04 15:56
Anonymous13-Feb-04 15:56 
GeneralRe: Using Interfaces Practically Pin
Nick Seng12-Feb-04 21:44
Nick Seng12-Feb-04 21:44 
GeneralRe: Using Interfaces Practically Pin
Brian Delahunty13-Feb-04 0:48
Brian Delahunty13-Feb-04 0:48 
GeneralRe: Using Interfaces Practically Pin
Jonathan de Halleux13-Feb-04 2:39
Jonathan de Halleux13-Feb-04 2:39 
GeneralRe: Using Interfaces Practically Pin
paw197213-Feb-04 5:33
paw197213-Feb-04 5:33 

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.