C# Programing FAQ - Post here

gayancc

Active member
  • Sep 8, 2007
    3,357
    8
    38
    my lap
    asachan said:
    I get it
    Machan that's cos you only put your Mouse Enter event for the visible parts of the form man. when form has a control on it , the control covers the Form's visible part so when you mouse over that control form's Mouse Over event never raise and your opacity translations wont work.

    One way to do this is override control's Mouse events. because windows from controls have independent Mouse event controls .

    let me have some time and may be i can find a way to thi


    thanx bro ur effort bt i found great way to fix it and now it work properly if u need tht i'll post it here :) :)
     
    Last edited:

    gayancc

    Active member
  • Sep 8, 2007
    3,357
    8
    38
    my lap
    i used a timer to accomplish that task so itz a greate way except using mouse enter and mouse leaver events here is the code snippet


    public partial class Form1 : Form
    {
    Timer timer1 = new Timer();

    public Form1()
    {
    InitializeComponent();
    this.Opacity = 0.10;
    timer1.Tick += new EventHandler(timer1_Tick);
    timer1.Interval = 200;
    timer1.Enabled = true;
    }

    void timer1_Tick(object sender, EventArgs e) {
    Point pos = Control.MousePosition;
    bool inForm = pos.X >= Left && pos.Y >= Top && pos.X < Right && pos.Y < Bottom;
    this.Opacity = inForm ? 0.99 : 0.10;
    }
    }
     

    asachan

    Member
    Apr 11, 2009
    1,636
    3
    0
    Athurugiriya
    chindaara said:
    i want to export a datagrid view to excel on a button click.how can i do that

    my database is a .mdf database.

    plz help me.

    Look machan i will help you to access to the Excel in C#
    and you need to do the rest. (Cus it's the easy part )

    1. add a referance to Excel object library .

    2. using Microsoft.Office.Interop.Excel;

    3. in your method here is how you gonna access excel runtime


    Microsoft.Office.Interop.Excel.Application excelApp = new Microsoft.Office.Interop.Excel.Application();
    Microsoft.Office.Interop.Excel.Workbook excelBook = excelApp.Workbooks.Add(XlWBATemplate.xlWBATWorksheet);
    Microsoft.Office.Interop.Excel._Worksheet excelWorksheet = (Microsoft.Office.Interop.Excel._Worksheet)excelBook.Worksheets.get_Item(1);
    excelApp.Visible = true;

    Try to understand this .
    what it will do is create a empty excel workbook and show it
    When you understand it reply and i will go forword
     

    chindaara

    Member
    Aug 9, 2007
    505
    1
    0
    මහරගම
    asachan said:
    Look machan i will help you to access to the Excel in C#
    and you need to do the rest. (Cus it's the easy part )

    1. add a referance to Excel object library .

    2. using Microsoft.Office.Interop.Excel;

    3. in your method here is how you gonna access excel runtime


    Microsoft.Office.Interop.Excel.Application excelApp = new Microsoft.Office.Interop.Excel.Application();
    Microsoft.Office.Interop.Excel.Workbook excelBook = excelApp.Workbooks.Add(XlWBATemplate.xlWBATWorksheet);
    Microsoft.Office.Interop.Excel._Worksheet excelWorksheet = (Microsoft.Office.Interop.Excel._Worksheet)excelBook.Worksheets.get_Item(1);
    excelApp.Visible = true;

    Try to understand this .
    what it will do is create a empty excel workbook and show it
    When you understand it reply and i will go forword



    "using Microsoft.Office.Interop.Excel;" this give me an error
    Error 5 The type or namespace name 'Office' does not exist in the namespace 'Microsoft' (are you missing an assembly)​
     

    chindaara

    Member
    Aug 9, 2007
    505
    1
    0
    මහරගම
    Database read-only

    When inserting data into the database this error occurs

    Code:
    Failed to update database "C:\PROGRAM FILES\SETUP\DATABASE.MDF"because the database is read-only

    Code:
    See the end of this message for details on invoking 
    just-in-time (JIT) debugging instead of this dialog box.
    
    ************** Exception Text **************
    System.Data.SqlClient.SqlException: Failed to update database "C:\PROGRAM FILES\SETUP\DATABASE.MDF" because the database is read-only.
       at Test_Project.TestDataSetTableAdapters.TableAdapterManager.UpdateAll(TestDataSet dataSet)
       at Test_Project.Form2.testDetailsBindingNavigatorSaveItem_Click(Object sender, EventArgs e)
       at System.Windows.Forms.ToolStripItem.RaiseEvent(Object key, EventArgs e)
       at System.Windows.Forms.ToolStripButton.OnClick(EventArgs e)
       at System.Windows.Forms.ToolStripItem.HandleClick(EventArgs e)
       at System.Windows.Forms.ToolStripItem.HandleMouseUp(MouseEventArgs e)
       at System.Windows.Forms.ToolStripItem.FireEventInteractive(EventArgs e, ToolStripItemEventType met)
       at System.Windows.Forms.ToolStripItem.FireEvent(EventArgs e, ToolStripItemEventType met)
       at System.Windows.Forms.ToolStrip.OnMouseUp(MouseEventArgs mea)
       at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
       at System.Windows.Forms.Control.WndProc(Message& m)
       at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
       at System.Windows.Forms.ToolStrip.WndProc(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
    
    
    ************** Loaded Assemblies **************
    mscorlib
        Assembly Version: 2.0.0.0
        Win32 Version: 2.0.50727.3053 (netfxsp.050727-3000)
        CodeBase: file:///C:/Windows/Microsoft.NET/Framework/v2.0.50727/mscorlib.dll
    ----------------------------------------
    Test Project
        Assembly Version: 1.0.0.0
        Win32 Version: 1.0.0.0
        CodeBase: file:///C:/Program%20Files/Setup/Test%20Project.exe
    ----------------------------------------

    can u give me a solution for this..
     

    navodwickra

    Well-known member
  • Jan 17, 2007
    11,416
    2,135
    113
    Leeds, UK
    chindaara said:
    When inserting data into the database this error occurs

    Code:
    Failed to update database "C:\PROGRAM FILES\SETUP\DATABASE.MDF"because the database is read-only

    Code:
    See the end of this message for details on invoking 
    just-in-time (JIT) debugging instead of this dialog box.
    
    ************** Exception Text **************
    System.Data.SqlClient.SqlException: Failed to update database "C:\PROGRAM FILES\SETUP\DATABASE.MDF" because the database is read-only.
       at Test_Project.TestDataSetTableAdapters.TableAdapterManager.UpdateAll(TestDataSet dataSet)
       at Test_Project.Form2.testDetailsBindingNavigatorSaveItem_Click(Object sender, EventArgs e)
       at System.Windows.Forms.ToolStripItem.RaiseEvent(Object key, EventArgs e)
       at System.Windows.Forms.ToolStripButton.OnClick(EventArgs e)
       at System.Windows.Forms.ToolStripItem.HandleClick(EventArgs e)
       at System.Windows.Forms.ToolStripItem.HandleMouseUp(MouseEventArgs e)
       at System.Windows.Forms.ToolStripItem.FireEventInteractive(EventArgs e, ToolStripItemEventType met)
       at System.Windows.Forms.ToolStripItem.FireEvent(EventArgs e, ToolStripItemEventType met)
       at System.Windows.Forms.ToolStrip.OnMouseUp(MouseEventArgs mea)
       at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
       at System.Windows.Forms.Control.WndProc(Message& m)
       at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
       at System.Windows.Forms.ToolStrip.WndProc(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
    
    
    ************** Loaded Assemblies **************
    mscorlib
        Assembly Version: 2.0.0.0
        Win32 Version: 2.0.50727.3053 (netfxsp.050727-3000)
        CodeBase: file:///C:/Windows/Microsoft.NET/Framework/v2.0.50727/mscorlib.dll
    ----------------------------------------
    Test Project
        Assembly Version: 1.0.0.0
        Win32 Version: 1.0.0.0
        CodeBase: file:///C:/Program%20Files/Setup/Test%20Project.exe
    ----------------------------------------

    can u give me a solution for this..


    change the attributes of the Database file 'DATABASE.MDF' so the program can access it and insert rows.