Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

charp variable

Posted on 2009-05-18
1
Medium Priority
?
238 Views
Last Modified: 2012-05-07
private void listBox1_DragOver(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent(DataFormats.FileDrop))
            {
                e.Effect = DragDropEffects.Copy;
            }
            else
            {
                e.Effect = DragDropEffects.None;
            }
        }



why we no need to declare  Type of  e.Effect      such as object e.Effect    or int  e.Effect

I am very new for csharp
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
 
using System.Data.SqlClient;
 
namespace CDLib
{
    public partial class CDEntry : Form
    {
        public CDEntry()
        {
            InitializeComponent();
        }
 
        private void label3_Click(object sender, EventArgs e)
        {
 
        }
 
        private void button1_Click(object sender, EventArgs e)
        {
            this.Close();
 
        }
 
        private void listBox1_DragOver(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent(DataFormats.FileDrop))
            {
                e.Effect = DragDropEffects.Copy;
            }
            else
            {
                e.Effect = DragDropEffects.None;
            }
        }
 
        private void listBox1_DragDrop(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent(DataFormats.FileDrop))
            {
                // Reads the Drop files int to a string array;
                string[] filePaths =
                    (string[])(e.Data.GetData(DataFormats.FileDrop));
 
                // Iteraction 
                foreach (string filename in filePaths)
                {
                    string keyword = Path.GetFileNameWithoutExtension(filename);
                    this.AddKeyWord(keyword);
                }
            }
 
        }
 
        int AddKeyWord(string keyword)
        {
            string lowercaseKeyword = keyword.ToLower();
 
            int idx = KeyWordList.Items.IndexOf(lowercaseKeyword);
            if (idx == -1)
            {
                KeyWordList.Items.Add(lowercaseKeyword);
 
            }
 
            return idx;
        }
 
        private void SaveButton_Click(object sender, EventArgs e)
        {
            // Validate Form fields
 
            if (tbCdName.Text.Length < 5)
            {
                MessageBox.Show("Please enter a valid CD Name (min. 5 Characters)");
                return;
 
            }
 
            if (KeyWordList.Items.Count < 1)
            {
                MessageBox.Show("Please add Key Words to the keyword List");
                return;
            }
 
            try
            {
                this.Opacity = 40.0;
                this.Enabled = false;
                this.Cursor = Cursors.WaitCursor;
 
                if (SaveData())
                {
                    MessageBox.Show("CD Entry saved succesfully!");
                    this.Close();
                }
            }
            finally
            {
                this.Opacity = 100.0;
                this.Enabled = true;
                this.Cursor = Cursors.Default;
            }
 
          
        }
 
 
        
        /// <summary>
        /// Store the CD Entry to the Database
        /// </summary>
        /// <returns></returns>
        bool SaveData()
        {
            bool result = false;
 
            int cdLibraryID = 0;
 
            //TODO: Use a transaction in this scope
            // Create a connection 
            using (SqlConnection conn = new SqlConnection(CDLib.Program.Connstring))
            {
                // Create SqlCommand. We use a T-SQL Store Procedure
                // to insert the Data in to the CdLibrary table
                using (SqlCommand cmd = new SqlCommand("insert_CdLibrary", conn))
                {
                    cmd.CommandType = CommandType.StoredProcedure;
 
                    cmd.Parameters.AddWithValue("@CdName", tbCdName.Text);
                    cmd.Parameters.AddWithValue("@CdDescription", tbCdDescription.Text);
                    cmd.Parameters.AddWithValue("@Location", tbCdLocation.Text);
                    cmd.Parameters.AddWithValue("@CdType", "");
 
 
                    try
                    {
                        conn.Open();
                        cdLibraryID = Convert.ToInt32(cmd.ExecuteScalar());
                    }
                    catch (Exception ex)
                    {
                        conn.Close();
                        MessageBox.Show(ex.Message);
                        return false;
                    }
                    
                }
                // Create SqlCommand. We use a T-SQL Store Procedure
                // to insert the Data in to the CdLibrary_keyword table
                using (SqlCommand cmd = new SqlCommand("insert_cdkeywords", conn))
                {
                    cmd.CommandType = CommandType.StoredProcedure;
 
                    cmd.Parameters.AddWithValue("@EntryCDID", cdLibraryID);
                    cmd.Parameters.AddWithValue("@KeyWordIDList", GetKeyWordList());
 
 
 
                    try
                    {
                        cmd.ExecuteScalar();
                    }
                    catch (Exception ex)
                    {
                        conn.Close();
                        MessageBox.Show(ex.Message);
                        return false;
                    }
 
 
                    result = true;
                }
            }
 
 
            return result;
        }
 
        private string GetKeyWordList()
        {
            string result = string.Empty;
 
            for (int i = 0; i < KeyWordList.Items.Count - 1; i++ )
            {
                result += KeyWordList.Items[i].ToString() + ';';
            }
 
            return result;
            
        }
 
        private void CancelButton_Click(object sender, EventArgs e)
        {
            this.Close();
        }
 
        private void AddKeyWordButton_Click(object sender, EventArgs e)
        {
 
            if(tbKeyWord.Text.Length < 5)
            {
                MessageBox.Show("Please enter a valid KeyWord (min. 5 Characters)");
                return;
 
            }
 
            if (AddKeyWord(tbKeyWord.Text) != -1)
            {
                MessageBox.Show(string.Format("Keyword :{0} allready exists! Please try again.", tbKeyWord.Text));
                return;
            }
 
        }
 
        private void KeyWordList_SelectedIndexChanged(object sender, EventArgs e)
        {
            int idx = KeyWordList.SelectedIndex;
            if (idx != -1)
            {
                tbKeyWord.Text = KeyWordList.Items[idx].ToString();
            }
        }
 
       
 
        private void contextMenuStrip1_Opening(object sender, CancelEventArgs e)
        {
            if (KeyWordList.SelectedIndex == -1)
                e.Cancel = true;
 
        }
 
        private void deleteToolStripMenuItem_Click(object sender, EventArgs e)
        {
             int idx = KeyWordList.SelectedIndex;
 
             if (idx != -1)
             {
                 DialogResult result =
                     MessageBox.Show("Are you sure you want to delete this item?", "", 
                     MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                 if(result == DialogResult.Yes)
                     KeyWordList.Items.RemoveAt(idx);
 
             }
        }
 
       
    }
}

Open in new window

0
Comment
Question by:teera
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 10

Accepted Solution

by:
oxyoo earned 2000 total points
ID: 24418714
Hi
The variable "e" is already declared as an DragEventArgs in the method as a parameter (DragEventArgs e) this means that you can use the variable e anywhere inside the listBox1_DragDrop method.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question