简体   繁体   中英

MonoDevelop button crash when clicked

You guys have been very helpful before, therefore I ask for your assistance again. Building a simple code. Customer plugs in information in the entries, and when they click the button, it saves in the XLS file.

public partial class MainWindow : Gtk.Window
{       
    public MainWindow (): base (Gtk.WindowType.Toplevel)
    {
        Build ();
    }

    protected void OnButton2Click (object sender, System.EventArgs e)
    {
        ExcelFile ef = new ExcelFile();
        // Loads the template file.
        ef.LoadXls(@"/home/sinnich/Documents/Database.xls");
        // Selects the first worksheet.
        ExcelWorksheet ws = ef.Worksheets[0];
        //Top informations
        ws.Cells["B1"].Value = "Computer navn";
        ws.Cells["C1"].Value = "Serial Nr";
        ws.Cells["D1"].Value = "Låners navn";
        ws.Cells["E1"].Value = "Telefon Nr";
        ws.Cells["F1"].Value = "Dato for udlån"; 
        ws.Cells["G1"].Value = "Forventet afleverings dato";
        //Editable info
        ws.Cells["B2"].Value = entry1;
        ws.Cells["C2"].Value = entry2;
        ws.Cells["D2"].Value = entry3;
        ws.Cells["E2"].Value = entry4; 
        ws.Cells["F2"].Value = entry5; 
        ws.Cells["G2"].Value = entry6;
        // Saves the file.
        ef.SaveXls(@"/home/sinnich/Documents/Database.xls");
        //Test af knappen.
        label7.Text = "Overført til database";
        throw new System.NotImplementedException ();
    }

    protected void OnDeleteEvent (object sender, DeleteEventArgs a)
    {
        Application.Quit ();
        a.RetVal = true;
    }
}

I get this error code when trying to run the button:

Marshaling clicked signal
Exception in Gtk# callback delegate
  Note: Applications can use GLib.ExceptionManager.UnhandledException to handle the exception.
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.NotSupportedException: Type Entry is not supported.
  at GemBox.Spreadsheet.ExcelFile.a (System.Type A_0) [0x00000] in <filename unknown>:0 
  at GemBox.Spreadsheet.ExcelCell.set_Value (System.Object value) [0x00000] in <filename unknown>:0 
  at MainWindow.OnButton2Click (System.Object sender, System.EventArgs e) [0x000ba] in /home/sinnich/Projects/Rental Laptops/Rental_Laptops/MainWindow.cs:31 
  at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&)
  at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in <filename unknown>:0 
  --- End of inner exception stack trace ---
  at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in <filename unknown>:0 
  at System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) [0x00000] in <filename unknown>:0 
  at System.Delegate.DynamicInvokeImpl (System.Object[] args) [0x00000] in <filename unknown>:0 
  at System.MulticastDelegate.DynamicInvokeImpl (System.Object[] args) [0x00000] in <filename unknown>:0 
  at System.Delegate.DynamicInvoke (System.Object[] args) [0x00000] in <filename unknown>:0 
  at GLib.Signal.ClosureInvokedCB (System.Object o, GLib.ClosureInvokedArgs args) [0x00000] in <filename unknown>:0 
  at GLib.SignalClosure.Invoke (GLib.ClosureInvokedArgs args) [0x00000] in <filename unknown>:0 
  at GLib.SignalClosure.MarshalCallback (IntPtr raw_closure, IntPtr return_val, UInt32 n_param_vals, IntPtr param_values, IntPtr invocation_hint, IntPtr marshal_data) [0x00000] in <filename unknown>:0 
   at GLib.ExceptionManager.RaiseUnhandledException(System.Exception e, Boolean is_terminal)
   at GLib.SignalClosure.MarshalCallback(IntPtr raw_closure, IntPtr return_val, UInt32 n_param_vals, IntPtr param_values, IntPtr invocation_hint, IntPtr marshal_data)
   at Gtk.Application.gtk_main()
   at Gtk.Application.Run()
   at Rental_Laptops.MainClass.Main(System.String[] args) in /home/sinnich/Projects/Rental Laptops/Rental_Laptops/Main.cs:line 18

Got no clue what to do.


If I comment out the code with entry it don't crash.

Anyway how I else can get the xls files updated with editable text?

Changed the following:

ws.Cells["B2"].Value = entry1.Text;
ws.Cells["C2"].Value = entry2.Text;
ws.Cells["D2"].Value = entry3.Text;
ws.Cells["E2"].Value = entry4.Text; 
ws.Cells["F2"].Value = entry5.Text; 
ws.Cells["G2"].Value = entry6.Text;

Deleted the following:

    throw new System.NotImplementedException ();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM