Datagridview sorting and fetch data from db

  • Thread starter Thread starter Mou_inn
  • Start date Start date
M

Mou_inn

Guest
when we click on datagridview header row then datagridview sort data but i want to sort data at db level and fetch data and populate grid.

so tell me how to know sort column and sort order when we click on datagridview header row. please guide me with sample code.

i got a bit of code which i may use to get column name on which user click and sort direction.

please see my sample code and help me to arrange the code to get my objective full fill.

private void dgv_ColumnHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
{

string column = dGV.Columns[e.ColumnIndex].DataPropertyName; //Use column name if you set it
if (column == "StudentId")
{
sorter = new StudentSorter(StudentSorter.SField.StudentId, SetOrderDirection(column));
}
else if (column == "Name")
{
sorter = new StudentSorter(StudentSorter.SField.Name, SetOrderDirection(column));
}

switch (gridViewColumn.HeaderCell.SortGlyphDirection)
{
case SortOrder.None:
case SortOrder.Ascending:
sort = "ASC";
break;
case SortOrder.Descending:
sort = "DESC";
break;
default:
throw new ArgumentOutOfRangeException();
}
}
thanks

Continue reading...
 
Back
Top