【问题标题】:Centering specific column in RadListView (Telerik, Winforms)在 RadListView 中居中特定列(Telerik,Winforms)
【发布时间】:2014-06-16 17:12:05
【问题描述】:

我在我的项目中使用 (Telerik) RadListView (Telerik.WinControls.UI.RadListView())。 列表视图有几列:

public MainForm()
{
    Telerik.WinControls.UI.ListViewDetailColumn newColumn;
    InitializeComponent();

    newColumn = new ListViewDetailColumn("ID", "ID");
    newColumn.Width = 250;
    newColumn.Visible = false;
    this.MyListView.Columns.Add(newColumn);

    newColumn = new ListViewDetailColumn("Name", "Name");
    newColumn.Width = 250;
    newColumn.Visible = true;
    this.MyListView.Columns.Add(newColumn);

    newColumn = new ListViewDetailColumn("Description", "Description");
    newColumn.Width = 250;
    newColumn.Visible = true;
    this.MyListView.Columns.Add(newColumn);

    newColumn = new ListViewDetailColumn("Costs", "Costs");
    newColumn.Width = 250;
    newColumn.Visible = true;
    this.MyListView.Columns.Add(newColumn);

我通过添加 ListViewDataItems 来手动填充列表视图:

foreach (Data.Tablename listEntry in ListOfTableEntries)
{
    ListViewDataItem newRow = new ListViewDataItem(listEntry.Id, new string[]{ listEntry.Name, listEntry.Description, listEntry.Costs});
    this.MyListView.Items.Add(newRow);
}

到目前为止一切顺利。但我没有发现如何格式化构成添加行的特定列。例如:右对齐成本。 我该怎么做(不右对齐所有其他列)?

谢谢

【问题讨论】:

  • 请提供完整代码,因为我从“ListViewDetailColumn”收到错误。
  • 你遇到了什么错误? (当我重写代码以在此处显示时,我看到我在“Telerik.WinControls.UI.ListViewDetailColumn”处出现了写入错误,但在显示的代码部分中我没有看到任何错误)。

标签: c# telerik radlistview


【解决方案1】:

尝试以下方法:

   private void radListView1_CellFormatting(object sender, ListViewCellFormattingEventArgs e)
   {
    if ((e.CellElement).Data.HeaderText == "ID")
    {
        if ((e.CellElement is DetailListViewDataCellElement))
        {
            e.CellElement.TextAlignment = ContentAlignment.TopRight;
        }
    }
    if ((e.CellElement).Data.HeaderText == "Name")
    {
        if ((e.CellElement is DetailListViewDataCellElement))
        {
            e.CellElement.TextAlignment = ContentAlignment.MiddleCenter;
        }

    //end so on
    }
}

【讨论】:

  • 效果很好(我在最终程序中使用 .Name 而不是 .Headertext ,因为后者可能会因本地化而有所不同,但这种方式非常好用)。 Tnx
猜你喜欢
  • 2021-11-10
  • 2012-07-11
  • 2016-03-09
  • 1970-01-01
  • 2017-06-22
  • 2017-01-06
  • 2011-09-24
  • 2015-03-03
  • 1970-01-01
相关资源
最近更新 更多