C# 在RadListView中对中特定列(Telerik、Winforms)
我正在我的项目中使用(Telerik)RadListView(Telerik.WinControls.UI.RadListView())。 listview有几个列:C# 在RadListView中对中特定列(Telerik、Winforms),c#,telerik,radlistview,C#,Telerik,Radlistview,我正在我的项目中使用(Telerik)RadListView(Telerik.WinControls.UI.RadListView())。 listview有几个列: public MainForm() { Telerik.WinControls.UI.ListViewDetailColumn newColumn; InitializeComponent(); newColumn = new ListViewDetailColumn("ID", "ID"); n
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添加ListViewDataItems来手动填充listview:
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);
}
到目前为止还不错。但我没有发现的是如何格式化组成添加行的特定列。例如:右对齐成本。
我如何才能做到这一点(不同时正确对齐所有其他列)
谢谢尝试以下几点:
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
}
}
请提供完整的代码,因为我从“ListViewDetailColumn”中得到了错误。您得到了什么错误?(当我重写代码在这里显示它时,我看到我在“Telerik.WinControls.UI.ListViewDetailColumn”处出现了一个书写错误,但在显示的代码部分中我没有看到任何错误)。这非常好地工作(我在最终程序中使用.Name而不是.Headertext,因为后者可能因本地化而有所不同,但功能非常好)。Tnx