Hello i try to to something like this
ID Column Text Column
|-----------------------------------------------|
| | TextBox1 |
ROW 0 | ID |------------------------------|
| | TextBox2 |
|-----------------------------------------------|
As far as i can tell i need to create my own Cell that does have 2 Texboxes in it and Paint that but i´m really not sure how do do that and i only found examples to add one component but not for more in a cell :). Can someone maybe give me an example ?
Thanks in advance ;)
DataGridView2TextBoxCell Class
using System;
using System.Drawing;
using System.Windows.Forms;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DataGRidViewCellTest
{
public class DataGridView2TextBoxCell : DataGridViewTextBoxCell
{
public override System.Type FormattedValueType
{
get
{
return Type.GetType("System.String");
}
}
protected override bool SetValue(int rowIndex, object value)
{
return base.SetValue(rowIndex, value);
}
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)
{
if ((paintParts & DataGridViewPaintParts.Background) ==
DataGridViewPaintParts.Background)
{
SolidBrush cellBackground =
new SolidBrush(cellStyle.BackColor);
graphics.FillRectangle(cellBackground, cellBounds);
cellBackground.Dispose();
}
if ((paintParts & DataGridViewPaintParts.Border) ==
DataGridViewPaintParts.Border)
{
PaintBorder(graphics, clipBounds, cellBounds, cellStyle,
advancedBorderStyle);
}
Rectangle TextBoxArea = cellBounds;
Rectangle TextBoxAdjustment = this.BorderWidths(advancedBorderStyle);
TextBoxArea.X += TextBoxAdjustment.X;
TextBoxArea.Y += TextBoxAdjustment.Y;
TextBoxArea.Height = TextBoxArea.Height/2;
TextBoxArea.Width -= TextBoxAdjustment.Width;
Rectangle TextBoxArea2 = cellBounds;
Rectangle TextBoxAdjustment2 = this.BorderWidths(advancedBorderStyle);
TextBoxArea2.X += TextBoxAdjustment2.X;
TextBoxArea2.Y += TextBoxAdjustment2.Y+TextBoxArea.Height;
TextBoxArea2.Height -= TextBoxArea.Height;
TextBoxArea2.Width -= TextBoxAdjustment2.Width;
this.ReadOnly = false;
base.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts);
if (TextBoxRenderer.IsSupported)
{
DataGridView2TextBoxColumn parent = (DataGridView2TextBoxColumn)this.OwningColumn;
string Value1 = "Encrypted";
string Value2 = Convert.ToString(value);
TextBoxRenderer.DrawTextBox(graphics, TextBoxArea, Value1, this.DataGridView.Font, System.Windows.Forms.VisualStyles.TextBoxState.Disabled);
TextBoxRenderer.DrawTextBox(graphics, TextBoxArea2, Value2, this.DataGridView.Font, System.Windows.Forms.VisualStyles.TextBoxState.Hot);
}
}
}
}
DataGridView2TextBoxColumn Class
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace DataGRidViewCellTest
{
public class DataGridView2TextBoxColumn : DataGridViewColumn
{
public DataGridView2TextBoxColumn()
{
this.CellTemplate = new DataGridView2TextBoxCell();
}
public void doSomething()
{
}
}
}