I just started using gtk# and I'm having some trouble with a simple problem. When I started a new project, I used MainWindow's Designer to create a basic UI with hbox/vbox and created an "Add Row" button and a 1-line table consisting of the headers of the table.
My problem is, on button click, I can't figure out how to dynamically add a row to my table.
Side note: My table in the Designer is labeled "table4", but I can't figure out how to access it. I figure once I can get help on how to properly access it, there should be an AddRow function where I can specify the height, margins, etc?
Thank you for your help.
Program.cs:
using System;
using Gtk;
namespace PMA
{
class MainClass
{
public static void Main (string[] args)
{
Application.Init ();
//create main window
MainWindow win = new MainWindow ();
Application.Run ();
}
}
}
MainWindow.cs:
using System;
using Gtk;
public partial class MainWindow: Gtk.Window
{
public MainWindow () : base (Gtk.WindowType.Toplevel)
{
Build ();
}
protected void OnDeleteEvent (object sender, DeleteEventArgs a)
{
Application.Quit ();
a.RetVal = true;
}
private void AddButtonPressHandler (object obj, EventArgs args)
{
Console.WriteLine("This works, but can't figure out how to dynamically add a row to MainWindow's table");
}
}
I don't know if this solves your problem but I think you can simply increase the NRows property. Put this instead of your AddButtonPressHandler method in MainWindow.cs:
private void AddButtonPressHandler (object obj, EventArgs args)
{
table4.NRows ++;
}
I hope it will work right.
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.