Infralution Support Forum Index Infralution Support
Support groups for Infralution products
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

drop on row - but which

 
Post new topic   Reply to topic    Infralution Support Forum Index -> Virtual Tree Support
View previous topic :: View next topic  
Author Message
egl



Joined: 27 Jun 2006
Posts: 15
Location: Switzerland

PostPosted: Tue Nov 21, 2006 4:43 pm    Post subject: drop on row - but which Reply with quote

hello,

i try to implement drag & drop on my virtual tree. so far, it works fine.
but now i want to find out on what row the object was dropped on.

how can i do that on the dragdrop eventhandler?

thank you
egl
Back to top
View user's profile Send private message
Infralution



Joined: 28 Feb 2005
Posts: 5027

PostPosted: Tue Nov 21, 2006 8:53 pm    Post subject: Reply with quote

Handle the RowDrop event (or override OnRowDrop). The row parameter is the row being dropped on. If you want the default behaviour for dropping data then you need to get the RowBinding and call the OnDrop method - then add your own code eg

Code:
RowBinding binding = GetBindingForRow(row);
if (binding != null)
{
     binding.OnDrop(row, dropLocation, data, dropEffect);
}
// add your own code after

_________________
Infralution Support
Back to top
View user's profile Send private message Visit poster's website
egl



Joined: 27 Jun 2006
Posts: 15
Location: Switzerland

PostPosted: Mon Nov 27, 2006 4:39 pm    Post subject: per drag & drop moved object dissapears. Reply with quote

hello,

i have to implement drag & drop of outlook-attachments to vt. after a while, i found a page which explanes the topic (
http://www.codeproject.com/csharp/testemaildragdrop.asp).
i more or less copied the code from there and adopted it to vt. but for some reason, the vt removes the attachment from outlook.
so i used the same peace of code for d&d-handling on a simple textbox and it worket. that showed me, that my problem has something to do with vt.

do you have any idea what it is? did i make a mistake on the implementation or is it a bug on vt?

code attached below

thanks you very much
egl

....
tree.DragEnter += new DragEventHandler(tree_DragEnter);
tree.DragDrop += new DragEventHandler(tree_DragDrop);
tree.GetAllowedRowDropLocations += new GetAllowedRowDropLocationsHandler(tree_GetAllowedRowDropLocations);

....

private void tree_DragDrop(object sender, DragEventArgs e) {
// mostly copied from htp://www.codeproject.com/csharp/ estemaildragdrop.asp
tree.SelectedItem = rowDroppedOn;
string tempFilePath = Path.GetTempPath();
string tempFilePath = @"c:\temp\";
string tempFileName = null;

try {
if ( e.Data.GetDataPresent(DataFormats.FileDrop,false) == true) {
string [] fileNames = null;
fileNames = (string []) e.Data.GetData(DataFormats.FileDrop);
// handle each file passed as needed
if (fileNames.Length > 0){
FileInfo origFileInfo = new FileInfo(fileNames[0]);
fileNames[0] = tempFilePath + origFileInfo.Name;

FileInfo tempFileInfo = new FileInfo(fileNames[0]);
if ( tempFileInfo.Exists == true) {
// for now, just delete what we created
tempFileInfo.Delete();
} File.Copy(origFileInfo.FullName, tempFileInfo.FullName) ;
tempFileName = tempFileInfo.FullName;
}
}
else if (e.Data.GetDataPresent("FileGroupDescriptor")) {

// Drop from Outlook - the first step here is to get the filename
// of the attachment and
// build a full-path name so we can store it
// in the temporary folder
//
// set up to obtain the FileGroupDescriptor
// and extract the file name
Stream theStream = (Stream) e.Data.GetData("FileGroupDescriptor");
byte [] fileGroupDescriptor = new byte[512];
theStream.Read(fileGroupDescriptor,0,512);
// used to build the filename from the FileGroupDescriptor block
StringBuilder fileName = new StringBuilder("");
// this trick gets the filename of the passed attached file
for(int i=76; fileGroupDescriptor[i]!=0; i++)
{ fileName.Append(Convert.ToChar(fileGroupDescriptor[i]));}
theStream.Close();

// create the full-path name
string theFile = tempFilePath+fileName.ToString();
// Second step: we have the file name.
// Now we need to get the actual raw
// data for the attached file and copy it to disk so we work on it. //
// get the actual raw file into memory
MemoryStream ms = (MemoryStream) e.Data.GetData("FileContents",true);
using (ms) {
// allocate enough bytes to hold the raw data
byte [] fileBytes = new byte[ms.Length];
// set starting position at first byte and read in the raw data
ms.Position = 0;
ms.Read(fileBytes,0,(int)ms.Length) ;
// create a file and save the raw zip file to it
FileStream fs = new FileStream(theFile,FileMode.Create);
fs.Write(fileBytes,0,(int)fileBytes.Length);
ms.Close();// close the memorystrem
fs.Close();// close the file
}
FileInfo tempFile = new FileInfo(theFile);
tempFileName = tempFile.FullName; }
if (tempFileName != null){
try {
dropedFilePath = tempFileName; ((PPDMBreakdownViewSet)SolutionModel.Instance.ActiveModule.Container.CurrentViewSet).newDocumentDrop.PerformAction();
} catch (Exception ex){
throw ex;
} finally {
File.Delete(tempFileName);
}
}
}
catch (Exception ex) {
// don't use MessageBox here - Outlook or Explorer is waiting !
Trace.WriteLine("Error in DragDrop function: " + ex.Message);
}
}

private void tree_GetAllowedRowDropLocations(object sender, GetAllowedRowDropLocationsEventArgs e) {
if (e.Row.Item is DataRowView && ((DataRowView)e.Row.Item).Row is DSBreakdown.ProjectDocumentRow){
DSBreakdown.ProjectDocumentRow row = (DSBreakdown.ProjectDocumentRow)((DataRowView)e.Row.Item).Row;
if (row.IsTemplateIDNull()){
e.AllowedDropLocations = RowDropLocation.OnRow;
rowDroppedOn = (DataRowView)e.Row.Item;
} else {
e.AllowedDropLocations = RowDropLocation.None;
}
} else {
e.AllowedDropLocations = RowDropLocation.None;
}
}

private void tree_DragEnter(object sender, DragEventArgs e){
if (e.Data.GetDataPresent(DataFormats.FileDrop)) {
e.Effect = DragDropEffects.Copy ;
}else if (e.Data.GetDataPresent("FileGroupDescriptor"))
{e.Effect = DragDropEffects.Copy ;}
else { e.Effect = DragDropEffects.None;}
}
Back to top
View user's profile Send private message
Infralution



Joined: 28 Feb 2005
Posts: 5027

PostPosted: Mon Nov 27, 2006 9:26 pm    Post subject: Re: per drag & drop moved object dissapears. Reply with quote

egl wrote:
but for some reason, the vt removes the attachment from outlook.


Do you mean that the drop succeeds but that the attachment is then removed from the original outlook email? If this is the case you may need to override the OnDragOver method and set the eventargs.Effect to DragDropEffects.Copy. The TextBox control may have this as the default.
_________________
Infralution Support
Back to top
View user's profile Send private message Visit poster's website
egl



Joined: 27 Jun 2006
Posts: 15
Location: Switzerland

PostPosted: Wed Nov 29, 2006 9:30 am    Post subject: Reply with quote

hello,

i finally found out what the problem was. I used the tree.DragDrop event instead of tree.RowDrop.
No idea why, but the same code on the RowDrop eventhandler does not remove the outlook-attachment

thanks anyway for your support
egl
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Infralution Support Forum Index -> Virtual Tree Support All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group