how to sort serial no inside gridview

Jun 8 2013 3:41 AM
Hi

I am having datagridview in c#

I populated data inside datagridview.

I created Serial No inside datagridview along with other columns.

If i click serial no head,the serial no is sorted.
If i do sorting in other columns,the serial no is also sorted.

How to avoid sorting serial no, if I click other column headers.

I have given the code below



dsstock = new DataSet();
dsstock = fetchDataSetValues(statement);
// grdStock.Rows.Clear();
if (dsstock.Tables[0].Rows.Count > 0)
{
grdStock.Columns.Add("Sl. No.", "Sl. No.");
grdStock.Columns[0].Width = 80;

grdStock.Columns.Add("ItemID", "Item ID");
grdStock.Columns[1].Width =300;
grdStock.Columns.Add("ItemName", "Item Name");
grdStock.Columns[2].Width = 600;
grdStock.Columns.Add("ItemQuantity", "Item Quantity");
grdStock.Columns[3].Width = 150;
int row = dsstock.Tables[0].Rows.Count - 1;

for (int r = 0; r <= row; r++)
{
grdStock.Rows.Add();
grdStock.Rows[r].Cells[0].Value = r + 1;
grdStock.Rows[r].Cells[1].Value = dsstock.Tables[0].Rows[r].ItemArray[0];
grdStock.Rows[r].Cells[2].Value = dsstock.Tables[0].Rows[r].ItemArray[1];
grdStock.Rows[r].Cells[3].Value = dsstock.Tables[0].Rows[r].ItemArray[2];

}
}
Thanks

Chandran

Answers (1)