C# DataGridView Hide Columns and Rows

The task of presenting data in a structured tabular format is one that you will undoubtedly encounter frequently in your endeavors. Recognizing this need, the DataGridView control emerges as an all-encompassing solution, purposefully designed to meet the demands of displaying tabular data within Windows Forms. Its careful design not only facilitates seamless data presentation but also empowers developers with an extensive array of configurable options, enabling customization of its appearance and behavior to align precisely with specific requirements.

Hide DataGridView Columns and Rows

The inherent adaptability of the DataGridView control sets it apart, offering a wealth of properties, methods, and events that enhance its configurability and extensibility. This expansive repertoire of features allows for precise tailoring of the control's visual presentation and operational characteristics. Developers can seamlessly manipulate and optimize various aspects, ranging from formatting and styling to interaction and data handling, ensuring an immaculate fit for the desired user experience and functional requirements.

The following C# source code manually creates a DataGridView columns and rows and hide the second column and second row.

dataGridView1.Rows[Index].Visible = false;
dataGridView1.Columns[Index].Visible = false;
Full Source C#
using System; using System.Data; using System.Windows.Forms; using System.Data.SqlClient; namespace WindowsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { dataGridView1.ColumnCount = 3; dataGridView1.Columns[0].Name = "Product ID"; dataGridView1.Columns[1].Name = "Product Name"; dataGridView1.Columns[2].Name = "Product Price"; string[] row = new string[] { "1", "Product 1", "1000" }; dataGridView1.Rows.Add(row); row = new string[] { "2", "Product 2", "2000" }; dataGridView1.Rows.Add(row); row = new string[] { "3", "Product 3", "3000" }; dataGridView1.Rows.Add(row); row = new string[] { "4", "Product 4", "4000" }; dataGridView1.Rows.Add(row); dataGridView1.Columns[1].Visible = false; dataGridView1.Rows[1].Visible = false; } } }


Through utilization of the DataGridView control provided by your tool, you can prettify your tabular data presentation to an unprecedented level, and hence the harmonization of functionality, beauty, and intuitiveness that are essential for data analysis and visualization is made possible with your user-friendly interface.