本文整理汇总了C#中ListView.SetObjects方法的典型用法代码示例。如果您正苦于以下问题:C# ListView.SetObjects方法的具体用法?C# ListView.SetObjects怎么用?C# ListView.SetObjects使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ListView
的用法示例。
在下文中一共展示了ListView.SetObjects方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SampleDesktop
//.........这里部分代码省略.........
TextBox txt = new TextBox();
txt.Text = "lorem ipsum";
txt.Size = new Squid.Point(222, 35);
txt.Position = new Point(110, 10 + 45 * i);
txt.Style = "textbox";
txt.AllowDrop = true;
txt.TabIndex = 1 + i;
txt.DragDrop += txt_OnDragDrop;
txt.GotFocus += txt_OnGotFocus;
panel.Content.Controls.Add(txt);
}
#endregion
#region sample window 6 - ListView
SampleWindow window6 = new SampleWindow();
window6.Size = new Point(440, 340);
window6.Position = new Point(960, 400);
window6.Resizable = true;
window6.Titlebar.Text = "Misc";
window6.Parent = this;
Random rnd = new Random();
List<MyData> models = new List<MyData>();
for (int i = 0; i < 32; i++)
{
MyData data = new MyData();
data.Name = rnd.Next().ToString();
data.Date = DateTime.Now.AddMilliseconds(rnd.Next());
data.Rating = rnd.Next();
models.Add(data);
}
ListView olv = new ListView();
olv.Dock = DockStyle.Fill;
olv.Columns.Add(new ListView.Column { Text = "Name", Aspect = "Name", Width = 120 });
olv.Columns.Add(new ListView.Column { Text = "Date", Aspect = "Date", Width = 120 });
olv.Columns.Add(new ListView.Column { Text = "Rating", Aspect = "Rating", Width = 120 });
olv.StretchLastColumn = false;
olv.FullRowSelect = true;
olv.CreateHeader = delegate(object sender, ListView.FormatHeaderEventArgs args)
{
Button header = new Button
{
Dock = DockStyle.Fill,
Text = args.Column.Text,
AllowDrop = true
};
header.MouseClick += delegate(Control snd, MouseEventArgs e)
{
if (args.Column.Aspect == "Name")
olv.Sort<MyData>((a, b) => a.Name.CompareTo(b.Name));
else if (args.Column.Aspect == "Date")
olv.Sort<MyData>((a, b) => a.Date.CompareTo(b.Date));
else if (args.Column.Aspect == "Rating")
olv.Sort<MyData>((a, b) => a.Rating.CompareTo(b.Rating));
};
header.MouseDrag += delegate(Control snd, MouseEventArgs e)
{
Label drag = new Label();
drag.Size = snd.Size;
drag.Position = snd.Location;
drag.Style = snd.Style;
drag.Text = ((Button)snd).Text;
DoDragDrop(drag);
};
header.DragDrop += delegate(Control snd, DragDropEventArgs e)
{
};
return header;
};
olv.CreateCell = delegate(object sender, ListView.FormatCellEventArgs args)
{
return new Button
{
Size = new Point(28, 28),
Dock = DockStyle.Top,
Text = olv.GetAspectValue(args.Model, args.Column),
Tooltip = args.Column.Text
};
};
olv.SetObjects(models);
window6.Controls.Add(olv);
#endregion
#endregion
}