Özel Komut Düğmeleri Oluşturma

Özel Komut Düğmeleri Oluşturma

Aspose.Cells.GridWeb’de özel bir komut düğmesi oluşturmak için:

  1. Aspose.Cells.GridWeb denetimini web formuna ekleyin.
  2. Bir çalışsayı açın.
  3. CustomCommandButton sınıfının bir örneğini oluşturun.
  4. Düğmenin Komutunu bir değere ayarlayın. Bu değer, düğmenin olay işleyicisinde kullanılır.
  5. Düğmenin metnini ayarlayın.
  6. Düğmenin görüntü URL’sini ayarlayın.
  7. Son olarak, CustomCommandButton nesnesini GridWeb denetiminin CustomCommandButtons koleksiyonuna ekleyin.

Kod parçacığının çıktısı aşağıda gösterilmiştir:

GridWeb denetimine özel bir komut düğmesi eklendi

todo:image_alt_text

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// Instantiating a CustomCommandButton object
CustomCommandButton button = new CustomCommandButton();
// Setting the command, text and image URL for button. Image should be relative to website root folder
button.Command = "MyButton";
button.Text = "MyButton";
button.ImageUrl = "../Image/aspose.ico";
// Adding button to CustomCommandButtons collection of GridWeb
GridWeb1.CustomCommandButtons.Add(button);

Özel Komut Düğmesi Olay İşleme

Özel komut düğmelerinin en önemli yönü, tıklanıldığında gerçekleştirdikleri eylemdir. Eylemi ayarlamak için, GridWeb denetiminin CustomCommand olayı için bir olay işleyici oluşturun.

CustomCommand olayı her zaman özel komut düğmesi tıklandığında tetiklenir. Bu nedenle, olay işleyicisinin, düğmeyi GridWeb denetimine eklerken ayarlanan Komutla bağlantılı belirli özel komut düğmesini tanımlaması gerekir. Son olarak, düğme tıklandığında yürütülen özel kodu ekleyin.

Aşağıdaki kod örneğinde, düğme tıklandığında A1 hücresine bir metin mesajı eklenir.

Özel komut düğmesine tıklandığında A1 hücresine eklenen metin

todo:image_alt_text

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// Creating Event Handler for CustomCommand event
protected void GridWeb1_CustomCommand(object sender, string command)
{
// Identifying a specific button by checking its command
if (command.Equals("MyButton"))
{
// Accessing the cells collection of the worksheet that is currently active
GridWorksheet sheet = GridWeb1.WorkSheets[GridWeb1.ActiveSheetIndex];
// Putting value to "A1" cell
sheet.Cells["A1"].PutValue("My Custom Command Button is Clicked.");
// Set first column width to make the text visible
sheet.Cells.SetColumnWidth(0, 30);
}
}