|
cannot fill a datagridview |
|
Hi,
Cannot seem to fill a datagridview.
For example sake I will try to keep it simple so that I can understand
3 columns (Names textbox -Titles ComboBox -JobTitle ComboBox.)
Open a project and cut and past the following which doesnt work!
Can you point out with code what to do to fill it?
Thanks a lot
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
SetupGridView();
LoadGridView();
}
private void SetupGridView()
{
dgv.ColumnCount = 3;
}
private void LoadGridView()
{
dgv.DataSource = GetNames();
dgv.Columns.Add(ColTitles());
dgv.Columns.Add(ColJobTitles());
}
private DataGridViewComboBoxColumn ColTitles()
{
//fill
DataGridViewComboBoxColumn clnTitle = new DataGridViewComboBoxColumn();
clnTitle.HeaderText = "Titles";
clnTitle.DataSource = GetTitles();
return clnTitle;
}
private DataGridViewComboBoxColumn ColJobTitles()
{
//fill
DataGridViewComboBoxColumn clnJobTitle = new DataGridViewComboBoxColumn();
clnJobTitle.HeaderText = "Job Titles";
clnJobTitle.DataSource = GetJobTitles();
return clnJobTitle;
}
private List<string> GetNames()
{
string[] names = new string[] { "Jo", "Fred", "John", "Robin" };
List<string> NameList = new List<string>(names);
return NameList;
}
private List<string> GetTitles()
{
string[] titles = new string[] { "Mr", "Mrs", "Dr", "Miss" };
List<string> TitleList = new List<string>(titles);
return TitleList;
}
private List<string> GetJobTitles()
{
string[] jobTitles = new string[] { "Manager", "Director", "Sales Manager", "Program Manager" };
List<string> JobTitleList = new List<string>(jobTitles);
return JobTitleList;
}
} | | vbjunkie Monday, February 27, 2006 2:49 PM |
|
|
You can use google to search for other answers |
|
|
|
|
|
More Threads |
|
| Regular Expression To Accept only (.) ? |
| Creating a tab/toolbar control that shows the MDI child windows opened |
| Button color |
| Help with a panel (or form) switching program |
| webbrowser used as file browser opens each folder in another windows |
| Problem with DropDownList in C# |
| MenuStrip problem |
| Windows service question |
| Lock a column in Table layout panel while scrolling. |
| Navigate between forms C# 2005 |
|