|
Hello.
It did not work. Any other suggestions?
this is the code that I use in the event:DataGridView_CellPainting
e.Paint(e.CellBounds, DataGridViewPaintParts.All - DataGridViewPaintParts.ContentBackground);
ControlPaint.DrawBorder(e.Graphics, e.CellBounds, System.Drawing.Color.Black, 1, ButtonBorderStyle.Solid, System.Drawing.Color.Black, 1, ButtonBorderStyle.Solid, System.Drawing.Color.Black, 1,
ButtonBorderStyle.Solid, System.Drawing.Color.Black, 1, ButtonBorderStyle.Solid);
e.Handled = true;
Thank you.
|
|
|
|
|
Hello.
I think it's not easy to set borders this way. One solution is to modify DataGridViewTextBoxCellEx.
Don't the standard behaviors (RowDividerWidth, ColumnDividerWidth, DataGridViewAdvancedBorderStyle) satisfy your requirements?
|
|
|
|
|
Nice post
tbhattacharjee
|
|
|
|
|
Hi, great idea, but manual would be great
modified 12-Dec-13 6:57am.
|
|
|
|
|
Hi. Thank you. I agree the article should be more detailed. You have resolved the problem, haven't you? So I'm sorry if you met some troubles and wasted your time. But I can not promise the description will be improved in near time. Sorry.
|
|
|
|
|
Sergey,
This looks exactly like what I am looking for in a WPF application. I have gone on the wpf.codeplex.com site and all I can find there are articles saying those types of features are not supported/not possible. Do you know of an implementation of this feature for WPF? And if not, how do you recommend creating it myself?
Thank you,
Eli
|
|
|
|
|
It is very useful.. Thanks...
|
|
|
|
|
This is GREAT! Why don't Microsoft buy this solution and add it to the next version? I am using VB 2010 and I add SpannedDataGridViewNet2.dll as a reference and Imports SpannedDataGridViewNet2. As soon as I define as follows Dim dgcTemp As SpannedDataGridViewNet2.DataGridViewTextBoxCellEx , I get this error.
As I understand this, I add yours cells to a Datagridview and the magic begins?
Unable to emit assembly: Referenced assembly 'SpannedDataGridViewNet2' does not have a strong name.
modified 30-Aug-13 9:47am.
|
|
|
|
|
Hi. Thanks.
Your assembly has a strong name, but SpannedDataGridViewNet2.dll has not. You may recompile the assembly SpannedDataGridViewNet2.dll, using strong name (signed by key), or add the sources to your project.
|
|
|
|
|
Thank You very much. It works eaxctly as expected!
|
|
|
|
|
i have problem to use your article.
datagridview does not contain a definition for singleverticalborderadded and singlehorizontalborderadded.
please your answer.
thank you...
|
|
|
|
|
Please, bring the code snippet that fails. I do not understand the question.
|
|
|
|
|
i resolved my problem to include datagridviewhelper.cs.
i have the another question.
if i do not use the columns editor because DB table data push into dataset same as table design
what is how to use the span function at runtime?
thank you..
|
|
|
|
|
Yes, it's a problem. I think, DataGridView logic, which is responsible for adding columns dynamically, should be changed for this. Or maybe other technics, which do not require changes, are exist, for example applying special attributes. In any case, additional investigation of DataGridView is required. So, now I don't know.
|
|
|
|
|
Excellent work, thank you for sharing it!
|
|
|
|
|
can you please release a .net 2.0 version?
thanks
|
|
|
|
|
Hi. I'm sorry for my late answer. I will port the code to .net 2.0 if you still need it. Thank you.
|
|
|
|
|
yes, i would appreciste the help, i really need this
|
|
|
|
|
Hi, I've released .net 2.0 version (see in sources).
|
|
|
|
|
when i set the double buffer of the span datagridview,why the background is black?
|
|
|
|
|
Following code worked for me. But I don't know why. Replace your Paint method with this:
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 (_ownerCell != null && _ownerCell.DataGridView == null)
{
_ownerCell = null;
}
if (DataGridView == null || (_ownerCell == null && _columnSpan == 1 && _rowSpan == 1))
{
base.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts);
return;
}
var ownerCell = this;
var columnIndex = ColumnIndex;
var columnSpan = _columnSpan;
var rowSpan = _rowSpan;
if (_ownerCell != null)
{
ownerCell = _ownerCell;
columnIndex = _ownerCell.ColumnIndex;
rowIndex = _ownerCell.RowIndex;
columnSpan = _ownerCell.ColumnSpan;
rowSpan = _ownerCell.RowSpan;
value = _ownerCell.GetValue(rowIndex);
errorText = _ownerCell.GetErrorText(rowIndex);
cellState = _ownerCell.State;
cellStyle = _ownerCell.GetInheritedStyle(null, rowIndex, true);
formattedValue = _ownerCell.GetFormattedValue(value, rowIndex, ref cellStyle, null, null, DataGridViewDataErrorContexts.Display);
}
if (CellsRegionContainsSelectedCell(columnIndex, rowIndex, columnSpan, rowSpan))
{
cellState |= DataGridViewElementStates.Selected;
}
RectangleF oldBounds = graphics.ClipBounds;
var cellBounds2 = DataGridViewCellExHelper.GetSpannedCellBoundsFromChildCellBounds(this, cellBounds, DataGridView.SingleVerticalBorderAdded(), DataGridView.SingleHorizontalBorderAdded());
clipBounds = DataGridViewCellExHelper.GetSpannedCellClipBounds(ownerCell, cellBounds2, DataGridView.SingleVerticalBorderAdded(), DataGridView.SingleHorizontalBorderAdded());
advancedBorderStyle = DataGridViewCellExHelper.AdjustCellBorderStyle(ownerCell);
using (var g = this.DataGridView.CreateGraphics())
{
g.SetClip(clipBounds);
ownerCell.NativePaint(g, clipBounds, cellBounds2, rowIndex, cellState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts & ~DataGridViewPaintParts.Border);
if ((paintParts & DataGridViewPaintParts.Border) != DataGridViewPaintParts.None)
{
var leftTopCell = ownerCell;
var advancedBorderStyle2 = new DataGridViewAdvancedBorderStyle
{
Left = advancedBorderStyle.Left,
Top = advancedBorderStyle.Top,
Right = DataGridViewAdvancedCellBorderStyle.None,
Bottom = DataGridViewAdvancedCellBorderStyle.None
};
leftTopCell.PaintBorder(g, clipBounds, cellBounds2, cellStyle, advancedBorderStyle2);
var rightBottomCell = DataGridView[columnIndex + columnSpan - 1, rowIndex + rowSpan - 1] as DataGridViewSpannedTextBoxCell ?? this;
var advancedBorderStyle3 = new DataGridViewAdvancedBorderStyle
{
Left = DataGridViewAdvancedCellBorderStyle.None,
Top = DataGridViewAdvancedCellBorderStyle.None,
Right = advancedBorderStyle.Right,
Bottom = advancedBorderStyle.Bottom
};
rightBottomCell.PaintBorder(g, clipBounds, cellBounds2, cellStyle, advancedBorderStyle3);
}
}
graphics.SetClip(clipBounds);
ownerCell.NativePaint(graphics, clipBounds, cellBounds2, rowIndex, cellState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts & ~DataGridViewPaintParts.Border);
if ((paintParts & DataGridViewPaintParts.Border) != DataGridViewPaintParts.None)
{
var leftTopCell = ownerCell;
var advancedBorderStyle2 = new DataGridViewAdvancedBorderStyle
{
Left = advancedBorderStyle.Left,
Top = advancedBorderStyle.Top,
Right = DataGridViewAdvancedCellBorderStyle.None,
Bottom = DataGridViewAdvancedCellBorderStyle.None
};
leftTopCell.PaintBorder(graphics, clipBounds, cellBounds2, cellStyle, advancedBorderStyle2);
var rightBottomCell = DataGridView[columnIndex + columnSpan - 1, rowIndex + rowSpan - 1] as DataGridViewSpannedTextBoxCell ?? this;
var advancedBorderStyle3 = new DataGridViewAdvancedBorderStyle
{
Left = DataGridViewAdvancedCellBorderStyle.None,
Top = DataGridViewAdvancedCellBorderStyle.None,
Right = advancedBorderStyle.Right,
Bottom = advancedBorderStyle.Bottom
};
rightBottomCell.PaintBorder(graphics, clipBounds, cellBounds2, cellStyle, advancedBorderStyle3);
}
graphics.SetClip(oldBounds);
}
|
|
|
|
|
Thank you very much. I'm very happy that the component is still in use. I will try to take into account your code as soon as possible. Thank you for your useful and very interesting investigation.
modified 5-Jun-13 14:26pm.
|
|
|
|
|
hi,tipsybroom, thanks for your reply, i have a question, where is "DataGridViewSpannedTextBoxCell" from?
|
|
|
|
|
I renamed DataGridViewTextBoxCellEx to DataGridViewSpannedTextBoxCell in my code
|
|
|
|
|
|