Home > DeveloperSection > Forums > DataGridView Sorting and Filtering C#.
Simons Hood
Simons Hood

Total Post:70

Posted on    June-15-2013 4:48 AM

 C# C# 

 1 Reply(s)
 3188  View(s)
Rate this:
Hi developers,

How to set Sorting and Filtering in datagridview using C#.

Sumit Kesarwani

Total Post:378

Posted on    June-15-2013 7:41 AM

Hi Samuel,

You can use this code:

using System;

using System.Data;

using System.Windows.Forms;

using System.Data.SqlClient;


namespace WindowsApplication1


    public partial class Form1 : Form


        public Form1()





        private void button1_Click(object sender, EventArgs e)


            string connectionString = "Data Source=.;Initial Catalog=pubs;Integrated Security=True";

            string sql = "SELECT * FROM Titles";

            SqlConnection connection = new SqlConnection(connectionString);

            SqlDataAdapter dataadapter = new SqlDataAdapter(sql, connection);

            DataSet ds = new DataSet();


            dataadapter.Fill(ds, "Titles_table");



            DataView dv;

            dv = new DataView(ds.Tables[0], "Price > 19", "Price Desc", DataViewRowState.CurrentRows);

            dataGridView1.DataSource = dv;




Don't want to miss updates? Please click the below button!

Follow MindStick