Workaround for 1px empty space between listviewitems

This commit is contained in:
Jaex 2014-06-05 16:47:37 +03:00
parent cd8deaaeb0
commit 8e58ad83b7
2 changed files with 32 additions and 11 deletions

View file

@ -29,9 +29,9 @@ protected override void Dispose(bool disposing)
private void InitializeComponent() private void InitializeComponent()
{ {
this.scMain = new System.Windows.Forms.SplitContainer(); this.scMain = new System.Windows.Forms.SplitContainer();
this.tcMain = new System.Windows.Forms.TabControl();
this.lvMain = new HelpersLib.MyListView(); this.lvMain = new HelpersLib.MyListView();
this.columnHeader2 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.columnHeader2 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.tcMain = new System.Windows.Forms.TabControl();
((System.ComponentModel.ISupportInitialize)(this.scMain)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.scMain)).BeginInit();
this.scMain.Panel1.SuspendLayout(); this.scMain.Panel1.SuspendLayout();
this.scMain.Panel2.SuspendLayout(); this.scMain.Panel2.SuspendLayout();
@ -59,6 +59,15 @@ private void InitializeComponent()
this.scMain.SplitterWidth = 3; this.scMain.SplitterWidth = 3;
this.scMain.TabIndex = 0; this.scMain.TabIndex = 0;
// //
// tcMain
//
this.tcMain.Dock = System.Windows.Forms.DockStyle.Fill;
this.tcMain.Location = new System.Drawing.Point(0, 0);
this.tcMain.Name = "tcMain";
this.tcMain.SelectedIndex = 0;
this.tcMain.Size = new System.Drawing.Size(460, 500);
this.tcMain.TabIndex = 0;
//
// lvMain // lvMain
// //
this.lvMain.AutoFillColumn = true; this.lvMain.AutoFillColumn = true;
@ -76,15 +85,7 @@ private void InitializeComponent()
this.lvMain.UseCompatibleStateImageBehavior = false; this.lvMain.UseCompatibleStateImageBehavior = false;
this.lvMain.View = System.Windows.Forms.View.Details; this.lvMain.View = System.Windows.Forms.View.Details;
this.lvMain.SelectedIndexChanged += new System.EventHandler(this.lvMain_SelectedIndexChanged); this.lvMain.SelectedIndexChanged += new System.EventHandler(this.lvMain_SelectedIndexChanged);
// this.lvMain.MouseUp += new System.Windows.Forms.MouseEventHandler(this.lvMain_MouseUp);
// tcMain
//
this.tcMain.Dock = System.Windows.Forms.DockStyle.Fill;
this.tcMain.Location = new System.Drawing.Point(0, 0);
this.tcMain.Name = "tcMain";
this.tcMain.SelectedIndex = 0;
this.tcMain.Size = new System.Drawing.Size(460, 500);
this.tcMain.TabIndex = 0;
// //
// TabToListView // TabToListView
// //

View file

@ -120,9 +120,28 @@ private void FillListView(TabControl tab)
} }
} }
private void lvMain_MouseUp(object sender, MouseEventArgs e)
{
if (lvMain.SelectedItems.Count == 0 && (e.Button == MouseButtons.Left || e.Button == MouseButtons.Right))
{
ListViewItem lvi = lvMain.GetItemAt(e.X, e.Y);
if (lvi == null)
{
// Workaround for 1px space between items
lvi = lvMain.GetItemAt(e.X, e.Y - 1);
}
if (lvi != null)
{
lvi.Selected = true;
}
}
}
private void lvMain_SelectedIndexChanged(object sender, EventArgs e) private void lvMain_SelectedIndexChanged(object sender, EventArgs e)
{ {
if (lvMain.SelectedItems != null && lvMain.SelectedItems.Count > 0) if (lvMain.SelectedItems.Count > 0)
{ {
TabPage tabPage = lvMain.SelectedItems[0].Tag as TabPage; TabPage tabPage = lvMain.SelectedItems[0].Tag as TabPage;
@ -131,6 +150,7 @@ private void lvMain_SelectedIndexChanged(object sender, EventArgs e)
tcMain.Visible = true; tcMain.Visible = true;
tcMain.TabPages.Clear(); tcMain.TabPages.Clear();
tcMain.TabPages.Add(tabPage); tcMain.TabPages.Add(tabPage);
lvMain.Focus();
} }
} }
} }