Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ListViewItem Border - Compact Framework

I have a ListView where I add as Items some ListViewItems. The View property is set to Details. When the ListView is displayed the ListViewItems haven't any border (top and bottom line that separates one item from another).

How can I do to add a border to all my items?

An example:

enter image description here

like image 917
Nick Avatar asked Mar 19 '13 19:03

Nick


2 Answers

For whatever reason, Gridlines aren't supported by the CF control, though the underlying native ListView does. P/Invoke to the rescue.

private const uint LVM_FIRST = 0x1000;
private const uint LVM_SETEXTENDEDLISTVIEWSTYLE = LVM_FIRST + 54;
private const uint LVM_GETEXTENDEDLISTVIEWSTYLE = LVM_FIRST + 55;
private const uint LVS_EX_GRIDLINES = 0x00000001;

[DllImport("coredll.dll")]
private static extern uint SendMessage(IntPtr hwnd, uint msg, uint wparam, uint lparam);

public void EnableGridlines(ListView listView)
{
    var style = SendMessage(
            listView.Handle,
            LVM_GETEXTENDEDLISTVIEWSTYLE,
            0,
            0);

    style |= LVS_EX_GRIDLINES;

    var style = SendMessage(
            listView.Handle,
            LVM_SETEXTENDEDLISTVIEWSTYLE,
            0,
            style);    
}
like image 130
ctacke Avatar answered Sep 21 '22 09:09

ctacke


ListView doesn't support GridLines in compact framework. You can use DataGridView

like image 22
albert Avatar answered Sep 24 '22 09:09

albert