我在C#中使用ListView来制作网格.我想找到一种能够以编程方式突出显示特定单元格的方法.我只需要突出显示一个单元格.
我已尝试使用所有者绘制的子项目,但使用下面的代码,我得到突出显示的单元格,但没有文字!有关于如何使其工作的任何想法?谢谢你的帮助.
//m_PC.Location is the X,Y coordinates of the highlighted cell.
void listView1_DrawSubItem(object sender, DrawListViewSubItemEventArgs e)
{
if ((e.ItemIndex == m_PC.Location.Y) && (e.Item.SubItems.IndexOf(e.SubItem) == m_PC.Location.X))
e.SubItem.BackColor = Color.Blue;
else
e.SubItem.BackColor = Color.White;
e.DrawBackground();
e.DrawText();
}
Run Code Online (Sandbox Code Playgroud) 我有一个列表视图,我想根据某些条件在不同的单元格中应用不同的字体.但我无法做到这一点.我尝试了这些类型的代码来添加项目.
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);
Run Code Online (Sandbox Code Playgroud)
和
ListViewItem …Run Code Online (Sandbox Code Playgroud)