Transform the procedure to the subprogramme



  • There is this sorting procedure:

    private void сортироватьЧастныеТаблицыToolStripMenuItem_Click(object sender, EventArgs e)
        {
         dataGridView2.Sort(dataGridView2.Columns["dataGridViewTextBoxColumn8"], ListSortDirection.Descending);
        }
    

    How can it be transformed into a subprogramme and how can it be called correctly?



  • It depends on how you want to use it. If you use it further to sort different dataGridView for different dataGridViewTextBoxColumn, you can put it in a separate method and give it the necessary parameters.

    void SortDataViewByColumn(GridView dataGridView, string nameColumn)
    {
        dataGridView.Sort(dataGridView.Columns[nameColumn], ListSortDirection.Descending);
    }
    

    Then for your example:

    private void сортироватьЧастныеТаблицыToolStripMenuItem_Click(object sender, EventArgs e)
    {
        SortDataViewByColumn(dataGridView2, "dataGridViewTextBoxColumn8");
    }
    



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2