相关疑难解决方法(0)

C#ListView详细信息,突出显示单个单元格

我在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)

c# listview highlight ownerdrawn

10
推荐指数
1
解决办法
3万
查看次数

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);
Run Code Online (Sandbox Code Playgroud)

ListViewItem …
Run Code Online (Sandbox Code Playgroud)

.net c# listview winforms

4
推荐指数
1
解决办法
5890
查看次数

标签 统计

c# ×2

listview ×2

.net ×1

highlight ×1

ownerdrawn ×1

winforms ×1