Quantcast

Dec 29, 2008

How to provide file drag-and-drop functionality in a Visual C# application

The step-by-step procedure that is outlined in this article demonstrates how to provide file drag-and-drop functionality in a Visual C# application. A ListBox control is used as the destination of the file drag-and-drop procedure.

Steps to Build the Sample

The ListBox control provides two drag-and-drop events that you need to handle: DragEnter and DragDrop. The DragEnter event occurs when you drag an object within the bounds of the control and is used to determine whether the object that is being dragged is one that you want to allow to be dropped on the control. You handle this event for cases in which a file or files are dragged to the control. This allows the appropriate icon to be displayed when the object is dragged over the control, depending on the object that is being dragged. The DragDrop event occurs when the object that is being dragged has been released on the control. You handle this event to retrieve the object. The Data object is used to retrieve the data.

The Data object's GetData method returns an array of strings that contain the full path names of the files that were dragged to the ListBox control. You can use this file path information to perform whatever operations are needed on the files. For example, you can use classes in the System.IO namespace to open and read the files, move the files, or copy the files to a new location. In this example, you just add the full path to the files that are dragged to the ListBox control.

To provide file drag-and-drop functionality in a Visual C# application, follow these steps:

1. Create a new Windows Forms application in Visual C# .NET or Visual C# 2005. Form1 is created by default.

2. Use the toolbox to add a ListBox control to Form1.

3. In the Properties window, change the AllowDrop property of the ListBox control to True to allow objects to be dragged onto the control.

4. In Solution Explorer, right-click Form1, and then click View Code.

5. To handle the DragEnter event, add the following method below the code section that the Windows Form Designer generates in the Form1 class:

 
 
 
 
private void listBox1_DragEnter(object sender, System.Windows.Forms.DragEventArgs e)
{
               if(e.Data.GetDataPresent(DataFormats.FileDrop))
                               e.Effect = DragDropEffects.All;
               else
                               e.Effect = DragDropEffects.None;
}
6.            To handle the DragDrop event, add the following method to the Form1 class immediately following the method that you added in step 5:
private void listBox1_DragDrop(object sender, System.Windows.Forms.DragEventArgs e)
{
               string[] s = (string[]) e.Data.GetData(DataFormats.FileDrop, false);
               int i;
               for(i = 0; i <>
                               listBox1.Items.Add(s[i]);
}
7.      To associate the two event handlers with the control events, add the following code in the Form1 constructor after the call to InitializeComponent:
this.listBox1.DragDrop += new           System.Windows.Forms.DragEventHandler(this.listBox1_DragDrop);
this.listBox1.DragEnter += new           System.Windows.Forms.DragEventHandler(this.listBox1_DragEnter);

8. Build and run the project.

9. Drag one or more files from either the desktop or another folder to the ListBox control. Note that the full path of the files is added to the ListBox control.


This post is from here and confers no rights

Dec 18, 2008

SQL Datetime Difference SAMPLE title

Step 1:Create a table for holding the datas of gantt chart.
Step 2:Create a trigger and call functions to update the columns

DURATION_HOURS, DURATION_MINUTES and DURATION_SECONDS from functions
Step 3:Create a function and use SQL datediff function to calculate the

date part

CREATE TABLE GANT_CHART
(
BATCH_NO VARCHAR(150) PRIMARY KEY,
RESOURCE_NAME VARCHAR(200),
START_TIME DATETIME,
END_TIME DATETIME,
DURATION_HOURS INT,
DURATION_MINUTES INT,
DURATION_SECONDS INT
)


CREATE TRIGGER DUR_CALC
ON WHBS_GANTT
FOR INSERT
AS
UPDATE GANT_CHART SET DURATION_HOURS = DBO.DATE_DIFF_HRS(START_TIME,END_TIME)
UPDATE GANT_CHART SET DURATION_MINUTES = DBO.DATE_DIFF_MIN(START_TIME,END_TIME)
UPDATE GANT_CHART SET DURATION_SECONDS = DBO.DATE_DIFF_SECS(START_TIME,END_TIME)


/*****************TIME DIFFERENCE HOURS FUNCTION**********************/
CREATE FUNCTION DATE_DIFF_HRS
(
@DATE1 DATETIME,
@DATE2 DATETIME
)
RETURNS INT
AS
BEGIN
RETURN CONVERT(INT,DATEDIFF(HOUR,@DATE1 ,@DATE2))
END

--DROP FUNCTION DATE_DIFF_HRS


/*****************TIME DIFFERENCE MINUTES FUNCTION**********************/
CREATE FUNCTION DATE_DIFF_MIN
(
@DATE1 DATETIME,
@DATE2 DATETIME
)
RETURNS INT
AS
BEGIN
RETURN CONVERT(INT,DATEDIFF(MINUTE,@DATE1 ,@DATE2)%60)
END

--DROP FUNCTION DATE_DIFF_MIN


/*****************TIME DIFFERENCE SECONDS FUNCTION**********************/
CREATE FUNCTION DATE_DIFF_SECS
(
@DATE1 DATETIME,
@DATE2 DATETIME
)
RETURNS INT
AS
BEGIN
RETURN CONVERT(INT,DATEDIFF(SECOND,@DATE1 ,@DATE2)%60)
END

Jan 10, 2008

whiteboarb

skrbl now