9

What form am I looking for? View data in table with events

 3 years ago
source link: https://www.codesd.com/item/what-form-am-i-looking-for-view-data-in-table-with-events.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

What form am I looking for? View data in table with events

advertisements

Total noob here, just playing around with C# (which is very cool btw).

Anyways, I need to display some information in a table. I have to have the ability to set the content of the rows and cols dynamicly using the code and one field in the table has to trigger an event in C#.

Filename #1         Click here to download
Filename #2         Click here to download

You get the idea Click here to download should trigger an event in C#. What kind of form type am I looking for? I've looked at almost all of them, but I can't figure out which one is the one best suited for this.

Using "Windows Form Application" btw.


The DataGridView control is basically what you are describing. The DataGridView has a LinkColumn type that acts like an HTML link. You just handle the CellContentClick event and determine which cell the user clicked on:

public Form1() {
  InitializeComponent();

  dataGridView1.Columns.Add(new DataGridViewTextBoxColumn() { ReadOnly = true });
  dataGridView1.Columns.Add(new DataGridViewLinkColumn());

  dataGridView1.Rows.Add(1);
  dataGridView1.Rows[0].Cells[0].Value = "File #1";
  dataGridView1.Rows[0].Cells[1].Value = "Click here";

  dataGridView1.CellContentClick += new DataGridViewCellEventHandler(dataGridView1_CellContentClick);
}

void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) {
  if (e.ColumnIndex == 1) {
    MessageBox.Show("Downloading " + dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString());
  }
}

Tags winforms

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK