コード例 #1
0
        public void LoadTable(IDataTable <T> table)
        {
            datatable = table;

            headers.Clear();
            FieldInfo[] fields = table.GetStructType().GetFields();
            foreach (FieldInfo info in fields)
            {
                DataTableHeader h = new DataTableHeader(info.Name);
                h.Clicked   += OnHeaderClicked;
                h.Repainted += OnRepaint;
                h.Resized   += OnResized;
                headers.Add(h);
            }
            keyHeader            = new DataTableHeader("Key", 80f);
            keyHeader.Repainted += OnRepaint;
            keyHeader.Resized   += OnResized;
            keyHeader.Clicked   += OnHeaderClicked;

            rows.Clear();
            table.ForEachEntries((string key, T value) =>
            {
                DataTableRow r = new DataTableRow(headers.Count, value, key);
                r.Clicked     += OnRowClicked;
                rows.Add(r);
            });
            OnSearchUpdated();
            RefreshRowSizes();
            Repaint();
        }
コード例 #2
0
        private void OnHeaderClicked(object sender, EventArgs e)
        {
            DataTableHeader header = ((DataTableHeader)sender);

            if (selectedHeader != header)
            {
                if (selectedHeader != null)
                {
                    selectedHeader.SetSelected(false);
                    selectedHeader = null;
                }
                selectedHeader = header;
                selectedHeader.SetSelected(true);
                selectedField = datatable.GetStructType().GetField(selectedHeader.name);
                if (header == keyHeader)
                {
                    rows.Sort(SortKeys);
                }
                else
                {
                    rows.Sort(SortSelected);
                }
            }
            else
            {
                rows.Reverse();
            }
            OnSearchUpdated();
            Repaint();
        }