paint a userdefined datagridviewcolumn

Hi experts

I created a datagridviewcolumn which contains a listview. But I'm struggling with displaying the whole thing.
As I understand it, every cell shares the same listview, so I can't just display the listview, right?

I think I need the Paint event of my custom cell to draw my content but I have no idea how.

thanks
public class DataGridViewListViewColumn : DataGridViewColumn
    {
        public DataGridViewListViewColumn()
            : base(new DataGridViewListViewCell())
        {
            
        }

public class DataGridViewListViewCell : DataGridViewTextBoxCell
    {
        public DataGridViewListViewCell()
            : base()
        {

        }

        public override void InitializeEditingControl(int rowIndex, object initialFormattedValue, DataGridViewCellStyle dataGridViewCellStyle)
        {
            base.InitializeEditingControl(rowIndex, initialFormattedValue, dataGridViewCellStyle);
            DataGridViewListView ctl = new DataGridViewListView();
            ctl.Show();
        }

        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, "", errorText, cellStyle, advancedBorderStyle, paintParts);
        }

        public override Type EditType
        {
            get
            {
                return typeof(DataGridViewListView);
            }
        }

        public override Type ValueType
        {
            get
            {
                return typeof(Int32);
            }
            set
            {
                base.ValueType = value;
            }
        }
    }

        public override DataGridViewCell CellTemplate
        {
            get
            {
                return base.CellTemplate;
            }
            set
            {
                if(value != null &&
                    !value.GetType().IsAssignableFrom(typeof(DataGridViewListViewCell)))
                {
                    throw new InvalidCastException("Must be a CalendarCell");
                }

                base.CellTemplate = value;
            }
        }
    }

Open in new window

LVL 3
ArikaelAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Roshan DavisCommented:
to paint a cell this link will help
http://stackoverflow.com/questions/177133/overriding-datagridviewtextboxcell-paint-method
pasting the part which I am referring
protected override void Paint(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates cellState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts) {

            DataGridViewPaintParts pp = DataGridViewPaintParts.Background | DataGridViewPaintParts.Border | DataGridViewPaintParts.ContentBackground
                | DataGridViewPaintParts.ErrorIcon;

            base.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, pp);

            string text = formattedValue as string; //<- HERE YOU NEED TO GIVE WHAT YOU WANT TO DISPLAY

            int indent = ((MyRow)OwningRow).Indent * INDENTCOEFFICIENT;
            strFmt.Trimming = StringTrimming.EllipsisCharacter;
            Rectangle r = cellBounds;
            r.Offset(indent, 0);
            r.Inflate(-indent, 0);
            graphics.DrawString(text, cellStyle.Font, Brushes.Black, r, strFmt);
        }

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ArikaelAuthor Commented:
please note that you have to change somethings in the code (for example changing MyRow to DataGridViewRow)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.