Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8752039
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T13:09:23+00:00 2026-06-13T13:09:23+00:00

I want to host a custom control for datagridviewcell . the only good reference

  • 0

I want to host a custom control for datagridviewcell.

the only good reference i have was http://msdn.microsoft.com/en-us/library/7tas5c80.aspx

However, i want the cell to display my own usercontrol instead on

 public class CustomCell : DataGridViewTextBoxCell
 {   
     protected override void Paint(System.Drawing.Graphics graphics,
       System.Drawing.Rectangle clipBounds, System.Drawing.Rectangle cellBounds,
        int rowIndex, DataGridViewElementStates cellState, object value, object 
          formattedValue, string errorText, DataGridViewCellStyle cellStyle,
            DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts)
     {
          base.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState, value, 
            formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts);               
     }
 }

Can anyone guide me how to do it ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T13:09:24+00:00Added an answer on June 13, 2026 at 1:09 pm

    In order to save on resources, the cells in a DataGridView control spend most of their time in display mode, only changing to edit mode when the user enters the cell using the mouse or keyboard. The example you referred to in your question is regarded as best practice, because the editing control (in that case, a DateTimePicker, but could just as easily be your own custom user control) only ever appears in edit mode, and thus only for one cell at a time.

    When the cell is not in edit mode, it should render an equivalent representation of its value using logic inside the Paint method of your subclass of DataGridViewCell. You could do this in one of several ways:

    • Simply draw text or an image onto the bounds of the cell based on its value; don’t try to replicate the way that the editing control looks.
    • Simulate the appearance of the editing control using ControlPaint or VisualStyleRenderer (note: this involves a lot of extra work).
    • Move the painting code from your custom user control into a utility class, so that both it and the cell can use the same painting code.

    In most cases, the first option will be sufficient; only attempt one of the other approaches if it is important for the cell to look EXACTLY the same as your editing control.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How to write a custom service host in WCF? I want to have more
I want to host StyleCop in a Custom Environment, the sample code provided in
I have a google web application project that I want to host on github.
I have a class library that I have written in C#.net. I want to
I am trying to host a custom Windows Forms control in WPF. My custom
I have a domain xyz.com whose registrar and web host are different. I have
HI, I want to customize the existing win-form tool-tip control to host child controls
I want to generate ssh public key using ssh-keygen with custom host name in
I have created a custom WPF user control which is intended to be used
I have a custom attribute that I want to apply to each methods in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.