我在我的项目中使用(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);
}
到目前为止一切顺利。我没有发现的是我如何格式化构成添加行的特定列。例如:右对齐成本。 我怎么能这样做(没有右对齐所有其他列)?
由于
答案 0 :(得分: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
}
}