Peter Kiers
asked on
Need code for Combobox SelectedIndexChanged-event
Dear Experts,
I want to try to make a Character Map just like Windows has. I have a combobox on my
form to get the System Fonts and I have used a DataGridView to display the characters.
Now only thing I need is to program the SelectedIndexChanged-event to display the
characters in DataGridView which belongs to the fontname when the user selects a font in the combobox. I have searched and found only vb-code that I don't understand. Who can help me?
Greetings, Peter Kiers
I want to try to make a Character Map just like Windows has. I have a combobox on my
form to get the System Fonts and I have used a DataGridView to display the characters.
Now only thing I need is to program the SelectedIndexChanged-event
characters in DataGridView which belongs to the fontname when the user selects a font in the combobox. I have searched and found only vb-code that I don't understand. Who can help me?
private const int NoOfCols = 16;
private const int ColWidth = 24;
public CharMap()
{
InitializeComponent();
}
private void CharMap_Load(object sender, EventArgs e)
{
//Set txtCopyChar as focus
this.ActiveControl = txtCopyChar;
//Get a list of font names into combo box.
InstalledFontCollection fc = new InstalledFontCollection();
foreach (FontFamily Item in fc.Families)
{
cboFontName.Items.Add(Item.Name);
}
cboFontName.SelectedIndex = 0;
//Setup datagrid
SetupDataGrid();
//Select the first item
CharGrid[1, 0].Selected = true;
}
private void SetupDataGrid()
{
//Number of columns to create.
CharGrid.ColumnCount = NoOfCols;
foreach (DataGridViewColumn Column in CharGrid.Columns)
{
//Set column width.
Column.Width = ColWidth;
}
//Add rows
CharGrid.Rows.Add(14);
//Add chars to data grid
AddCharsToGrid(0, 32);
AddCharsToGrid(1, 48);
AddCharsToGrid(2, 64);
AddCharsToGrid(3, 80);
AddCharsToGrid(4, 96);
AddCharsToGrid(5, 112);
AddCharsToGrid(6, 128);
AddCharsToGrid(7, 144);
AddCharsToGrid(8, 160);
AddCharsToGrid(9, 176);
AddCharsToGrid(10, 196);
AddCharsToGrid(11, 208);
AddCharsToGrid(12, 224);
AddCharsToGrid(13, 240);
}
private void AddCharsToGrid(int Row, int Index)
{
for (int Counter = 0; Counter <= 15; Counter++)
{
CharGrid[Counter, Row].Value = (char)(Index + Counter);
}
}
Greetings, Peter Kiers
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER