Search code examples
c#objectlistview

Objectlistview tooltip string padding


i want my olv show tooltip when user hover a row and i want to format output string as a table.

Here is my code:

args.Title = "Danh sách sản phẩm";
HoaDon hoadon = args.Model as HoaDon;
args.StandardIcon = ToolTipControl.StandardIcons.Info;
StringBuilder str = new StringBuilder();
foreach (var chitiet in hoadon.DSChiTietHD)
{
     str.AppendLine();
     str.Append(chitiet.SanPham.MaSP.ToString().PadRight(10));
     str.Append(chitiet.SanPham.TenSP.PadRight(50));
     str.Append(chitiet.SoLuong.ToString().PadRight(10));
}
args.Text = str.ToString();

but here is the result:

enter image description here

I'dont know what happened with 2nd column. Please help!


Solution

  • Its probably because you are not using a Mono-Space font. The "space" char is much smaller than the "u". Naturally, the padding only considers the number of chars, not the width. Change the font to "Courier" for example, that should fix it.