ListView子项字体不起作用
我有一个列表视图,我想根据某些条件在不同的单元格中应用不同的字体。但我无法做到这一点。我尝试使用这些类型的代码来添加项目。
ListViewItem entryListItem = listView_Standard.Items.Add("Items");
// Set UseItemStyleForSubItems property to false to change
// look of subitems.
entryListItem.UseItemStyleForSubItems = false;
// Add the expense subitem.
ListViewItem.ListViewSubItem expenseItem =
entryListItem.SubItems.Add("Expense");
// Change the expenseItem object's color and font.
expenseItem.ForeColor = System.Drawing.Color.Red;
expenseItem.Font = new System.Drawing.Font(
"Arial", 10, System.Drawing.FontStyle.Italic);
// Add a subitem called revenueItem
ListViewItem.ListViewSubItem revenueItem =
entryListItem.SubItems.Add("Revenue");
revenueItem.BackColor = System.Drawing.Color.Red;
// Change the revenueItem object's color and font.
revenueItem.ForeColor = System.Drawing.Color.Blue;
revenueItem.Font = new System.Drawing.Font(
"KF-Kiran", 25, System.Drawing.FontStyle.Bold);
当
ListViewItem NewItem = new ListViewItem();
NewItem.UseItemStyleForSubItems = false;
NewItem.Text = "foo";
NewItem.SubItems.Add("bar");
NewItem.SubItems.Add("1111111");
NewItem.SubItems[1].Font = new Font("KF-Kiran", 20);
listView_Standard.Items.Add(NewItem);
我使用第 0 个子项更改字体时,新字体将应用于整行。但我只希望特定的单元格应用字体。
I have a listview in which I want to apply different font in different cells according to some condition. But I'm unable to do this. I tried these types of codes to add item.
ListViewItem entryListItem = listView_Standard.Items.Add("Items");
// Set UseItemStyleForSubItems property to false to change
// look of subitems.
entryListItem.UseItemStyleForSubItems = false;
// Add the expense subitem.
ListViewItem.ListViewSubItem expenseItem =
entryListItem.SubItems.Add("Expense");
// Change the expenseItem object's color and font.
expenseItem.ForeColor = System.Drawing.Color.Red;
expenseItem.Font = new System.Drawing.Font(
"Arial", 10, System.Drawing.FontStyle.Italic);
// Add a subitem called revenueItem
ListViewItem.ListViewSubItem revenueItem =
entryListItem.SubItems.Add("Revenue");
revenueItem.BackColor = System.Drawing.Color.Red;
// Change the revenueItem object's color and font.
revenueItem.ForeColor = System.Drawing.Color.Blue;
revenueItem.Font = new System.Drawing.Font(
"KF-Kiran", 25, System.Drawing.FontStyle.Bold);
and
ListViewItem NewItem = new ListViewItem();
NewItem.UseItemStyleForSubItems = false;
NewItem.Text = "foo";
NewItem.SubItems.Add("bar");
NewItem.SubItems.Add("1111111");
NewItem.SubItems[1].Font = new Font("KF-Kiran", 20);
listView_Standard.Items.Add(NewItem);
When I use 0th subitem to change font, new font is applied to whole row. But I want only particluarl cells to apply font.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这会拒绝将第一个子项目的字体样式自动应用于所有子项目。
This denies first subitem's font style to be applied automatically on all subitems.