ningshuxia
2025-03-27 afbafeecc1325bff849a17fb63b9b2b65b48ddf1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
namespace Yw.WinFrmUI
{
    /// <summary>
    ///
    /// </summary>
    public static class ListBoxControlExtensions
    {
        /// <summary>
        ///
        /// </summary>
        public static void InitialDefaultSettings(this ListBoxControl listBox, int ItemHeight = 25)
        {
            listBox.ShowFocusRect = false;
            listBox.ItemHeight = ItemHeight;
        }
 
        /// <summary>
        /// 获取当前数据行
        /// </summary>
        public static T GetCurrentViewModel<T>(this ListBoxControl listBox, IEnumerable<T> source) where T : class
        {
            if (source == null)
                return default;
            if (source.Count() < 1)
            {
                return default;
            }
            var row = listBox.SelectedItem as T;
            if (row == null)
            {
                return null;
            }
            return row;
        }
    }
}