void ledgerStyleButton_Click( Object^ /*sender*/, System::EventArgs^ /*e*/ )
{
// Create a new cell style.
DataGridViewCellStyle^ style = gcnew DataGridViewCellStyle;
{
style->BackColor = Color::Beige;
style->ForeColor = Color::Brown;
style->Font = gcnew System::Drawing::Font( "Verdana",8 );
}
// Apply the style as the default cell style.
dataGridView1->AlternatingRowsDefaultCellStyle = style;
ledgerStyleButton->Enabled = false;
}
void SetUpDataGridView()
{
this->Controls->Add( dataGridView1 );
dataGridView1->ColumnCount = 5;
DataGridViewCellStyle^ style = dataGridView1->ColumnHeadersDefaultCellStyle;
style->BackColor = Color::Navy;
style->ForeColor = Color::White;
style->Font = gcnew System::Drawing::Font( dataGridView1->Font,FontStyle::Bold );
dataGridView1->EditMode = DataGridViewEditMode::EditOnEnter;
dataGridView1->Name = "dataGridView1";
dataGridView1->Location = Point(8,8);
dataGridView1->Size = System::Drawing::Size( 500, 300 );
dataGridView1->AutoSizeRowsMode = DataGridViewAutoSizeRowsMode::DisplayedCellsExceptHeaders;
dataGridView1->ColumnHeadersBorderStyle = DataGridViewHeaderBorderStyle::Raised;
dataGridView1->CellBorderStyle = DataGridViewCellBorderStyle::Single;
dataGridView1->GridColor = SystemColors::ActiveBorder;
dataGridView1->RowHeadersVisible = false;
dataGridView1->Columns[ 0 ]->Name = "Release Date";
dataGridView1->Columns[ 1 ]->Name = "Track";
dataGridView1->Columns[ 1 ]->DefaultCellStyle->Alignment = DataGridViewContentAlignment::MiddleCenter;
dataGridView1->Columns[ 2 ]->Name = "Title";
dataGridView1->Columns[ 3 ]->Name = "Artist";
dataGridView1->Columns[ 4 ]->Name = "Album";
// Make the font italic for row four.
dataGridView1->Columns[ 4 ]->DefaultCellStyle->Font = gcnew System::Drawing::Font( DataGridView::DefaultFont,FontStyle::Italic );
dataGridView1->SelectionMode = DataGridViewSelectionMode::FullRowSelect;
dataGridView1->MultiSelect = false;
dataGridView1->BackgroundColor = Color::Honeydew;
dataGridView1->Dock = DockStyle::Fill;
dataGridView1->CellFormatting += gcnew DataGridViewCellFormattingEventHandler( this, &Form1::dataGridView1_CellFormatting );
dataGridView1->CellParsing += gcnew DataGridViewCellParsingEventHandler( this, &Form1::dataGridView1_CellParsing );
addNewRowButton->Click += gcnew EventHandler( this, &Form1::addNewRowButton_Click );
deleteRowButton->Click += gcnew EventHandler( this, &Form1::deleteRowButton_Click );
ledgerStyleButton->Click += gcnew EventHandler( this, &Form1::ledgerStyleButton_Click );
dataGridView1->CellValidating += gcnew DataGridViewCellValidatingEventHandler( this, &Form1::dataGridView1_CellValidating );
}
void PopulateDataGridView()
{
// Create the string array for each row of data.
array<String^>^row0 = {"11/22/1968","29","Revolution 9","Beatles","The Beatles [White Album]"};
array<String^>^row1 = {"4/4/1960","6","Fools Rush In","Frank Sinatra","Nice 'N' Easy"};
array<String^>^row2 = {"11/11/1971","1","One of These Days","Pink Floyd","Meddle"};
array<String^>^row3 = {"4/4/1988","7","Where Is My Mind?","Pixies","Surfer Rosa"};
array<String^>^row4 = {"5/1981","9","Can't Find My Mind","Cramps","Psychedelic Jungle"};
array<String^>^row5 = {"6/10/2003","13","Scatterbrain. (As Dead As Leaves.)","Radiohead","Hail to the Thief"};
array<String^>^row6 = {"6/30/1992","3","Dress","P J Harvey","Dry"};
// Add a row for each string array.
{
DataGridViewRowCollection^ rows = this->dataGridView1->Rows;
rows->Add( row0 );
rows->Add( row1 );
rows->Add( row2 );
rows->Add( row3 );
rows->Add( row4 );
rows->Add( row5 );
rows->Add( row6 );
}
// Change the order the columns are displayed.
{
DataGridViewColumnCollection^ columns = this->dataGridView1->Columns;
columns[ 0 ]->DisplayIndex = 3;
columns[ 1 ]->DisplayIndex = 4;
columns[ 2 ]->DisplayIndex = 0;
columns[ 3 ]->DisplayIndex = 1;
columns[ 4 ]->DisplayIndex = 2;
}
}