First of all, I apologise that I will post my samples in C#, please use Telerik's Converter to convert the code to VB.NET
Recently, I've been dealing a lot with this problem. I've researched and documented the whole framework just to see if there is any good way of achieving it, there was none.
When I saw your question, I have decided to take an hour, focus and to dig up some more and found a very messy way of achieving it, prior to the other messy way I've been using all along. For the interested programmers, what I did up until now was activate Double Buffering to DataGridView control, either through reflection or inheritance, mixing with WS_EX_COMPOSITED activation.
Which worked like this:
public class DataGridViewV2 : DataGridView
{
protected override CreateParams CreateParams
{
get
{
CreateParams cp = base.CreateParams;
cp.ExStyle = cp.ExStyle | 0x02000000;
return cp;
}
}
public DataGridViewV2()
{
SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
SetStyle(ControlStyles.AllPaintingInWmPaint, true);
SetStyle(ControlStyles.UserPaint, true);
SetStyle(ControlStyles.DoubleBuffer, true);
}
}
This greatly reduced the vertical splitter showing up. And it would suffice in most cases unless it really bothers the inconsistency of your design or you are a perfectionist.
Okay, now going to the current method I've just found:
This is the main method that draws our ugly problem, it is a private one we can do nothing to manipulate what it does. I've been jumping from code to code, and have found that it relies on a private variable called currentColSplitBar whether it will be drawn or not. Jackpot! All we have to do is use reflection, to edit the variable to always stick to -1 value to against the condition from drawing it on the PaintGrid method and it will never show up.
The drawing of the splitter starts once we click a cell's resizable divider and it lasts until we release the click, so naturally, we want to edit the variable on MouseDown event and MouseMove event. So all we have to do is reuse the previous method, while also, assign new handlers to these events.
public class DataGridViewV2 : DataGridView
{
public DataGridViewV2()
{
SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
SetStyle(ControlStyles.AllPaintingInWmPaint, true);
SetStyle(ControlStyles.UserPaint, true);
SetStyle(ControlStyles.DoubleBuffer, true);
MouseDown += (sender, e) => PreventXOR_Region();
MouseMove += (sender, e) => PreventXOR_Region();
}
private void PreventXOR_Region()
{
FieldInfo field = typeof(DataGridView).GetField("currentColSplitBar", BindingFlags.Instance | BindingFlags.NonPublic);
field.SetValue(this, -1);
}
protected override CreateParams CreateParams
{
get
{
CreateParams cp = base.CreateParams;
cp.ExStyle = cp.ExStyle | 0x02000000;
return cp;
}
}
}
Messy, but it works!