Click here to Skip to main content
15,888,610 members
Home / Discussions / .NET (Core and Framework)
   

.NET (Core and Framework)

 
QuestionVS2005 Help Problem Pin
Mike Hankey10-Jun-07 16:49
mveMike Hankey10-Jun-07 16:49 
AnswerRe: VS2005 Help Problem Pin
Sathesh Sakthivel10-Jun-07 20:00
Sathesh Sakthivel10-Jun-07 20:00 
GeneralRe: VS2005 Help Problem Pin
Mike Hankey11-Jun-07 1:12
mveMike Hankey11-Jun-07 1:12 
GeneralRe: VS2005 Help Problem Pin
Sathesh Sakthivel11-Jun-07 2:38
Sathesh Sakthivel11-Jun-07 2:38 
QuestionValidation Pin
imran_Shaikh10-Jun-07 1:54
imran_Shaikh10-Jun-07 1:54 
AnswerRe: Validation Pin
Christian Graus10-Jun-07 13:49
protectorChristian Graus10-Jun-07 13:49 
QuestionMaskedTextBox + KeyEventArgs.SuppressKeyPress = bug? Pin
alex3_148-Jun-07 6:37
alex3_148-Jun-07 6:37 
QuestionCustom DataGridViewComboBoxColumn Pin
MaverickDQ8-Jun-07 5:01
MaverickDQ8-Jun-07 5:01 
Hi
I'm trying to implement a custom Color DataGridViewComboBoxColumn that shows a color list.

My problem is that Colors that I'm adding into Items collection appear several time and I cannot figure why.

Below is an archive with an example project with source code.

Example

Here is the code that creates a custom Cell:
<code>
public class DataGridViewColorComboBoxCell : DataGridViewComboBoxCell
{
  private Color[] colorItems = { Color.Red, Color.Green, Color.Blue };
  Color c;
  protected int inMargin;
  protected int boxWidth;
  public DataGridViewColorComboBoxCell():base()
  {
    inMargin = 2;
    boxWidth = 3; 
    for (Int32 i = 0; i < colorItems.Length; i++)
    {
      this.Items.Add(colorItems[i].ToArgb().ToString());
    }
  }
  protected override object GetFormattedValue(
    object value,
    int rowIndex,
    ref DataGridViewCellStyle cellStyle,
    System.ComponentModel.TypeConverter valueTypeConverter,
    System.ComponentModel.TypeConverter formattedValueTypeConverter,
    DataGridViewDataErrorContexts context)
  {
    return (value);
  }
  public override Type EditType
  {
    get {return typeof(DataGridViewColorComboEditingControl);}
  }
  public override void InitializeEditingControl(
    int rowIndex, 
    object initialFormattedValue, 
    DataGridViewCellStyle dataGridViewCellStyle)
  {
    base.InitializeEditingControl(
      rowIndex, 
      initialFormattedValue, 
      dataGridViewCellStyle);
    DataGridViewColorComboEditingControl ctrl = 
      DataGridView.EditingControl as DataGridViewColorComboEditingControl;
    ctrl.ownerCell = this;
  }
  protected override void Paint(
    Graphics graphics, 
    Rectangle clipBounds, 
    Rectangle cellBounds, 
    int rowIndex, 
    DataGridViewElementStates elementState, 
    object value, 
    object formattedValue, 
    string errorText, 
    DataGridViewCellStyle cellStyle, 
    DataGridViewAdvancedBorderStyle advancedBorderStyle, 
    DataGridViewPaintParts paintParts)
  {
    base.Paint(
      graphics, 
      clipBounds, 
      cellBounds, 
      rowIndex, 
      elementState, 
      value, 
      formattedValue, 
      errorText, 
      cellStyle, 
      advancedBorderStyle, 
      paintParts);
    if (formattedValue != null && formattedValue.ToString() != "")
    {
      c = Color.FromArgb(Convert.ToInt32((string)formattedValue));
      Graphics g = graphics;
      g.FillRectangle(new SolidBrush(c), 
        cellBounds.X + this.inMargin, 
        cellBounds.Y + this.inMargin, 
        cellBounds.Width - (2 * this.inMargin + 1), 
        cellBounds.Height - (2 * this.inMargin + 1));
      g.DrawRectangle(Pens.Black, 
        cellBounds.X + this.inMargin, 
        cellBounds.Y + this.inMargin, 
        cellBounds.Width - (2 * this.inMargin + 1), 
        cellBounds.Height - (2 * this.inMargin + 1));
    }
  }
}
</code>

As you can see I'm adding colors to Items collection in cell constructor only. Normally it should show only 3 colours in combobox, but I get 3 times more , as you can see in screen below:

Image

So, I think I'm missing some important point in creating custom columns. Might not fully understand the whole picture of how it works and should be done.

Could someone point me where is the problem?

Thanks,
Alexandru
AnswerRe: Custom DataGridViewComboBoxColumn Pin
Robert Rohde8-Jun-07 21:48
Robert Rohde8-Jun-07 21:48 
GeneralRe: Custom DataGridViewComboBoxColumn Pin
MaverickDQ8-Jun-07 22:44
MaverickDQ8-Jun-07 22:44 
QuestionWorkflowFoundation: How to (un)persist types from different assembly versions Pin
Lord Skeletor8-Jun-07 2:31
Lord Skeletor8-Jun-07 2:31 
AnswerRe: WorkflowFoundation: How to (un)persist types from different assembly versions Pin
Kevin McFarlane8-Jun-07 6:37
Kevin McFarlane8-Jun-07 6:37 
GeneralRe: WorkflowFoundation: How to (un)persist types from different assembly versions Pin
Lord Skeletor10-Jun-07 23:18
Lord Skeletor10-Jun-07 23:18 
QuestionString to Byte Array Conversion Pin
M. J. Jaya Chitra8-Jun-07 1:21
M. J. Jaya Chitra8-Jun-07 1:21 
AnswerRe: String to Byte Array Conversion Pin
szukuro8-Jun-07 1:37
szukuro8-Jun-07 1:37 
AnswerRe: String to Byte Array Conversion Pin
Thomas Stockwell12-Jun-07 4:27
professionalThomas Stockwell12-Jun-07 4:27 
GeneralRe: String to Byte Array Conversion Pin
WhiteGirl2325-Jun-07 0:47
WhiteGirl2325-Jun-07 0:47 
Questionremoting service Pin
hoang minh khoi8-Jun-07 0:19
hoang minh khoi8-Jun-07 0:19 
AnswerRe: remoting service Pin
Manas Bhardwaj8-Jun-07 0:28
professionalManas Bhardwaj8-Jun-07 0:28 
Questioncan you help me Pin
hoang minh khoi8-Jun-07 0:09
hoang minh khoi8-Jun-07 0:09 
AnswerRe: can you help me Pin
szukuro8-Jun-07 1:42
szukuro8-Jun-07 1:42 
GeneralRe: can you help me Pin
hoang minh khoi8-Jun-07 15:14
hoang minh khoi8-Jun-07 15:14 
QuestionInstall two setup at same time Pin
Suhail Shahab7-Jun-07 20:46
Suhail Shahab7-Jun-07 20:46 
AnswerRe: Install two setup at same time Pin
Manas Bhardwaj8-Jun-07 0:27
professionalManas Bhardwaj8-Jun-07 0:27 
QuestionConnect FileMaker Pin
M. J. Jaya Chitra7-Jun-07 20:41
M. J. Jaya Chitra7-Jun-07 20:41 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.