0

How to sort a datagridview column on radiobutton checkchanged? When i try the below code an Exception is raised

private void rdoBookedOn_CheckedChanged(object sender, EventArgs e)
    {
        DataGridViewColumn bkon = grdBookingView.Columns[3];

        grdBookingView.Columns[3].SortMode = DataGridViewColumnSortMode.Programmatic;
        this.grdBookingView.Sort(this.bkon, ListSortDirection.Descending);

    }

ArgumentException is raised on this line

this.grdBookingView.Sort(this.bkon, ListSortDirection.Descending);

I've tried this in designer

this.grdBooking.AutoGenerateColumns = false;

The screenshot of the gridview

enter image description here

leppie
  • 115,091
  • 17
  • 196
  • 297
saurabh64
  • 363
  • 1
  • 4
  • 24
  • `this.bkon` ? Shouldn't it be local `bkon` (**without this**)? – Sinatr Jan 08 '15 at 11:16
  • @Sinatr I had just copied the sort code from net. What's the difference between this.bkon and local bkon? – saurabh64 Jan 08 '15 at 11:21
  • 1
    See [here](http://stackoverflow.com/q/23250/1997232). If it was *compiler error*, then you have to read about `this`. If it was *runtime exception*, then you have somewhere field/property in form class with name `bkon` (same as your local variable). – Sinatr Jan 08 '15 at 11:24

0 Answers0