Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

datagridview customization

Status
Not open for further replies.

HeatherG

Programmer
Jun 13, 2007
6
GB
Hi, I am new to C# and need a bit of guidence. I have a datgridview control which is populated by a binding source. I would like one of my columns to be a comboboxcell so after the grid is populated I have loop for the column I wish to change and set this :

public Boolean prSetColType(String pColName)
{
if (pColName == "TITLE")
{
DataGridViewColumn strCol = grdHeather.Columns [pColName];
DataGridViewComboBoxCell cellstyle = new DataGridViewComboBoxCell();
strCol.CellTemplate = cellstyle;
return true;
}
else
{
return false;
}
}

But it falls over on line :strCol.CellTemplate = cellstyle;
with error message must be derived from DataGridViewTextBoxCell.

Can anyone help please
 
I think the clue is in the error message.. It sounds to me like you need to add the Column to the Columns collection instead of trying to overwrite one that inherits from a different class. Maybe?

Age is a consequence of experience
 
If I understand you crrectly I don't think you need to do this.... open your form which has the datagridview and click the datagridview once. You'll see a little black arrow top right hand corner of the datagridview. Click it and then click the 'edit columns' option. Select the column that you wish to be a combbox and then look at the 'ColumnType' property. Simply change this to the combobox option and you should be good to go!
 
Thank you moongirl129, but I want to programatically create the columns.
 
what are you binding to the gridview?

you can set up the columns on the wizard converting them to templates fields, that way you can put in anything you want

so you can can fire an onRowDatabound method, and search for the control within that row and generate the values in the ddl and set the value.
 
nicklieb.. This a DataGridView not a GridView. Is there such an event?

Age is a consequence of experience
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top