How do I hide the gridlines or set them to a particular color?

Started by nandagopal, Jul 03, 2008, 08:46 PM

Previous topic - Next topic

nandagopal

DataGrid..GridLineColor
     DataGrid.GridLineStyle


private void Form1_Load(object sender, System.EventArgs e)
{
     // Set the connection and sql strings
     // assumes your mdb file is in your root
     string connString = @"Provider=Microsoft.JET.OLEDB.4.0;data source=C:\northwind.mdb";
     string sqlString = "SELECT * FROM customers";

     OleDbDataAdapter dataAdapter = null;
     DataSet _dataSet = null;

     try
     {
          // Connection object
          OleDbConnection connection = new OleDbConnection(connString);

          // Create data adapter object
          dataAdapter = new OleDbDataAdapter(sqlString, connection);
     
          // Create a dataset object and fill with data using data adapter's Fill method
          _dataSet = new DataSet();
          dataAdapter.Fill(_dataSet, "customers");
          connection.Close();
     }
     catch(Exception ex)
     {     
          MessageBox.Show("Problem with DB access-\n\n connection: "
               + connString + "\r\n\r\n query: " + sqlString
               + "\r\n\r\n\r\n" + ex.ToString());
          this.Close();
          return;
     }

     // Create a table style that will hold the new column style
     // that we set and also tie it to our customer's table from our DB
     DataGridTableStyle tableStyle = new DataGridTableStyle();
     tableStyle.MappingName = "customers";
     tableStyle.GridLineColor = dataGrid1.BackColor;
     
     dataGrid1.TableStyles.Add(tableStyle);
     dataGrid1.DataSource = _dataSet.Tables["customers"];

}