本文整理汇总了C#中System.Windows.Forms.ListView.AutoResizeColumns方法的典型用法代码示例。如果您正苦于以下问题:C# ListView.AutoResizeColumns方法的具体用法?C# ListView.AutoResizeColumns怎么用?C# ListView.AutoResizeColumns使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Forms.ListView
的用法示例。
在下文中一共展示了ListView.AutoResizeColumns方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: changeHardwareDetails
// This subroutine is a shortcut that changes the detail-list data on-screen if dropdown selectors are changed
// It also plays a part in initialisation
private void changeHardwareDetails(object hardwareInstance, ListView list)
{
// Clear the list
list.Items.Clear();
if (hardwareInstance != null)
{
// Get the properties of the given hardware class
FieldInfo[] classFields = hardwareInstance.GetType().GetFields();
string name, value;
// Loop through each field in the class
foreach (FieldInfo field in classFields)
{
// Extract the field name (format it)
name = fieldToString(field.Name);
// Extract the value
value = Convert.ToString(field.GetValue(hardwareInstance));
// If the value is zero or blank, output N/A
if (value == "0" || value == "") value = "N/A";
// Add the value to the list
list.Items.Add(new ListViewItem(new string[] {
name,
value
}));
}
// Resize columns
list.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent);
// Make last column fill the remaining width
list.Columns[list.Columns.Count - 1].Width = -2;
}
}
示例2: FillActiveUserFilesListViewDetailView
public static void FillActiveUserFilesListViewDetailView(IList<ActiveUserFile> activeUserFiles, ListView target)
{
FillActiveUserFilesListView(activeUserFiles, target);
target.View = View.Details;
target.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize);
target.Columns[target.Columns.Count - 1].Width = -2;
}
示例3: PopulateListView
void PopulateListView(ListView lv, List<KeyValuePair<string, Type>> map, Predicate<KeyValuePair<string, Type>> match)
{
lv.Visible = false;
lv.BeginUpdate();
lv.Items.Clear();
string fmt = "{0:D" + (map.Count.ToString().Length) + "}";
int order = 0;
foreach (var kvp in map)
{
order++;
if (!match(kvp)) continue;
string tag = getTag(kvp.Key);
string wrapper = kvp.Value.Name;
string file = System.IO.Path.GetFileName(kvp.Value.Assembly.Location);
string title = GetAttrValue(kvp.Value.Assembly, typeof(System.Reflection.AssemblyTitleAttribute), "Title");
string description = GetAttrValue(kvp.Value.Assembly, typeof(System.Reflection.AssemblyDescriptionAttribute), "Description");
string company = GetAttrValue(kvp.Value.Assembly, typeof(System.Reflection.AssemblyCompanyAttribute), "Company");
string product = GetAttrValue(kvp.Value.Assembly, typeof(System.Reflection.AssemblyProductAttribute), "Product");
ListViewItem lvi = new ListViewItem(new string[] { String.Format(fmt, order), tag, kvp.Key, wrapper, file, title, description, company, product, });
lvi.Tag = kvp;
lv.Items.Add(lvi);
}
if (lv.Items.Count > 0)
lv.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent);
lv.EndUpdate();
lv.Visible = true;
}
示例4: doSort
void doSort(ListView lv)
{
lv.Sort();
if (lv.Items.Count > 0)
lv.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent);
if (lv.SelectedItems.Count > 0)
lv.EnsureVisible(lv.SelectedIndices[0]);
}
示例5: Results
public Results(ListView lv, String[] headers)
{
this.listView = lv;
foreach (String header in headers)
listView.Columns.Add(new ColumnHeader() {
Text = header,
TextAlign = HorizontalAlignment.Left });
listView.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize);
}
示例6: ListViewColumnResize
public static void ListViewColumnResize(ListView lstview)
{
int[] ColumnWidth = new int[lstview.Columns.Count];
lstview.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent);
for (int i = 0; i < lstview.Columns.Count; i++)
{
ColumnWidth[i] = lstview.Columns[i].Width;
}
lstview.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize);
for (int i = 0; i < lstview.Columns.Count; i++)
{
ColumnWidth[i] = Math.Max(lstview.Columns[i].Width, ColumnWidth[i]);
}
for (int i = 0; i < lstview.Columns.Count; i++)
{
lstview.Columns[i].Width = ColumnWidth[i];
}
}
示例7: AutoResizePage
public static void AutoResizePage(ListView lv, int containerWidth)
{
if (lv == null || lv.Columns == null || lv.Columns.Count < 2)
{
return;
}
int numColumns = lv.Columns.Count;
int minColumnWidth = (containerWidth / numColumns) / 2;
int widthExpansion = containerWidth;
int columnMargin = 10;
lv.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent);
for (int i = 1; i < numColumns; i++)
{
widthExpansion -= lv.Columns[i].Width;
}
if (widthExpansion <= 0)
{
return;
}
for (int i = 1; i < numColumns; i++)
{
int requestedIncrease = 0;
if (lv.Columns[i].Width + columnMargin < minColumnWidth)
{
requestedIncrease = minColumnWidth - lv.Columns[i].Width;
}
else
{
requestedIncrease = columnMargin;
}
if (requestedIncrease > 0)
{
if (requestedIncrease > widthExpansion)
{
requestedIncrease = widthExpansion;
}
lv.Columns[i].Width += requestedIncrease;
widthExpansion -= requestedIncrease;
}
}
}
示例8: AutoResizeColumns
private static void AutoResizeColumns(ListView lv)
{
lv.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent);
ListView.ColumnHeaderCollection cc = lv.Columns;
for (int i = 0; i < cc.Count; i++) {
int colWidth = TextRenderer.MeasureText(cc[i].Text, lv.Font).Width + 10;
if (colWidth > cc[i].Width) {
cc[i].Width = colWidth;
}
}
}
示例9: createListView
public void createListView(ListView listView, String responseDate, String responseString)
{
// Add the group, using the date for the response data as the group name.
ListViewGroup responseDateGroup = new ListViewGroup (responseDate);
listView.Groups.Add (responseDateGroup);
// This ensures that each entry is put on a separate line.
listView.AutoResizeColumns (ColumnHeaderAutoResizeStyle.ColumnContent);
// Without clearing the listview first, duplicate elements will appear.
if (listView.Groups.Count == 1)
{
listView.Clear ();
}
// Display each response on a separate line.
ListViewItem responseStringItem;
String[] responses = responseString.Split ('\n');
foreach (string word in responses)
{
responseStringItem = new ListViewItem (word, responseDateGroup);
listView.Items.Add (responseStringItem);
}
}
示例10: SetupColumns
private void SetupColumns(ListView ListView, String[] Headers)
{
ListView.Columns.Clear();
foreach (var Header in Headers)
{
AddColumn(ListView, Header);
}
ListView.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent);
ListView.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize);
}
示例11: PopulateListView
//Populates a list view.
private void PopulateListView(ListView lv, int productID)
{
vendorSourceList = _vendorSourceManager.GetVendorSourceItemsByProduct(productID);
lv.Items.Clear();
lv.Columns.Clear();
foreach (var vendorSource in vendorSourceList)
{
var item = new ListViewItem();
item.Text = vendorSource.Name;
item.SubItems.Add(String.Format("{0:C}", vendorSource.UnitCost));
item.SubItems.Add(vendorSource.MinQtyToOrder.ToString());
item.SubItems.Add(vendorSource.ItemsPerCase.ToString());
lv.Items.Add(item);
}
lv.Columns.Add("Vendor Name");
lv.Columns.Add("Unit Cost");
lv.Columns.Add("Min Order Qty");
lv.Columns.Add("Case Qty");
lv.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize);
}
示例12: Init
//.........这里部分代码省略.........
splitContainer1.Location = new Point(0, 48);
splitContainer1.Name = "splitContainer1";
splitContainer1.Panel1MinSize = 30;
splitContainer1.Panel2MinSize = 30;
splitContainer1.Panel1.Controls.Add(m_curvesListView);
splitContainer1.Panel2.Controls.Add(m_curveControl);
splitContainer1.Size = new Size(898, 520);
splitContainer1.SplitterDistance = 180;
splitContainer1.SplitterIncrement = 5;
splitContainer1.TabIndex = 0;
splitContainer1.TabStop = false;
splitContainer1.Text = "splitContainer1";
splitContainer1.BorderStyle = BorderStyle.None;
splitContainer1.SplitterWidth = 4;
splitContainer1.FixedPanel = FixedPanel.Panel1;
splitContainer1.SplitterMoved += splitContainer1_SplitterMoved;
splitContainer1.SplitterMoving += splitContainer1_SplitterMoving;
// list view
m_curvesListView.CheckBoxes = true;
m_curvesListView.Dock = DockStyle.Fill;
m_curvesListView.HideSelection = false;
m_curvesListView.LabelEdit = false;
m_curvesListView.Location = new Point(0, 0);
m_curvesListView.Name = "m_curvesListView";
m_curvesListView.Size = new Size(300, 300);
m_curvesListView.TabIndex = 0;
m_curvesListView.TabStop = false;
m_curvesListView.TileSize = new Size(250, 24);
m_curvesListView.UseCompatibleStateImageBehavior = false;
m_curvesListView.View = View.Details;
m_curvesListView.Sorting = SortOrder.Ascending;
m_curvesListView.ItemChecked += m_curvesListView_ItemChecked;
m_curvesListView.Scrollable = true;
m_curvesListView.Columns.Add("Curves", 250);
m_curvesListView.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize);
m_curvesListView.AllowColumnReorder = false;
m_curvesListView.BackColor = m_curveControl.BackColor;
var addMenuItem = new ToolStripMenuItem("Add Point".Localize());
var listMenuStrip = new ContextMenuStrip();
m_curvesListView.ContextMenuStrip = listMenuStrip;
listMenuStrip.Opening += delegate
{
addMenuItem.Enabled = m_curvesListView.SelectedItems.Count > 0;
};
listMenuStrip.Items.Add(addMenuItem);
addMenuItem.Click += delegate
{
if (m_curvesListView.SelectedItems.Count == 0)
return;
var dlg = new AddPointDialog();
dlg.Location = new Point(MousePosition.X, MousePosition.Y);
dlg.ShowDialog(this);
if (dlg.DialogResult != DialogResult.OK)
return;
PointF pt = dlg.PointPosition;
m_curveControl.TransactionContext.DoTransaction(delegate
{
foreach (ListViewItem item in m_curvesListView.SelectedItems)
{
var curve = (ICurve)item.Tag;
IControlPoint cpt = curve.CreateControlPoint();
float x = pt.X;
int index = CurveUtils.GetValidInsertionIndex(curve, x);
while (index == -1)
{
x += CurveUtils.Epsilone;
index = CurveUtils.GetValidInsertionIndex(curve, x);
}
cpt.X = x;
cpt.Y = pt.Y;
curve.InsertControlPoint(index, cpt);
CurveUtils.ComputeTangent(curve);
}
}, "Add Point".Localize());
m_curveControl.Invalidate();
};
ClientSize = new Size(898, 575);
Dock = DockStyle.Fill;
Controls.Add(splitContainer1);
Controls.Add(m_bottomStrip);
Controls.Add(m_topStrip);
Controls.Add(m_menu);
// resume layouts.
splitContainer1.Panel1.ResumeLayout(false);
splitContainer1.Panel2.ResumeLayout(false);
splitContainer1.ResumeLayout(false);
ResumeLayout(false);
PerformLayout();
Invalidated += CurveEditorControl_Invalidated;
SetUI(false);
Application.Idle += Application_Idle;
}
示例13: PopulateTermListView
//Populates a list view.
private void PopulateTermListView(ListView lv, List<ShippingTerm> termList)
{
_myTermManager.ShippingTerms = termList;
lv.Items.Clear();
lv.Columns.Clear();
foreach (var term in termList)
{
var item = new ListViewItem();
item.Text = term.Id.ToString();
//item.SubItems.Add(term.ShippingVendorId.ToString());
item.SubItems.Add(term.ShippingVendorName);
if (term.Description.Length > 25)
{
item.SubItems.Add(term.Description.Substring(0, 25));
}
else
{
item.SubItems.Add(term.Description);
}
item.SubItems.Add(term.Active.ToString());
lv.Items.Add(item);
}
lv.Columns.Add("Term ID");
//lv.Columns.Add("Vendor ID");
lv.Columns.Add("Vendor Name");
lv.Columns.Add("Description");
lv.Columns.Add("Active");
lv.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize);
}
示例14: FillCollectionStatusToList
//.........这里部分代码省略.........
lstData.Columns.Add("AverageObjectSize");
lstData.Columns.Add("PaddingFactor");
}
else
{
lstData.Columns.Add(SystemManager.mStringResource.GetText(StringResource.TextType.Collection_Status_CollectionName));
lstData.Columns.Add(SystemManager.mStringResource.GetText(StringResource.TextType.Collection_Status_ObjectCount));
lstData.Columns.Add(SystemManager.mStringResource.GetText(StringResource.TextType.Collection_Status_DataSize));
lstData.Columns.Add(SystemManager.mStringResource.GetText(StringResource.TextType.Collection_Status_LastExtentSize));
lstData.Columns.Add(SystemManager.mStringResource.GetText(StringResource.TextType.Collection_Status_StorageSize));
lstData.Columns.Add(SystemManager.mStringResource.GetText(StringResource.TextType.Collection_Status_TotalIndexSize));
//2012-3-6
lstData.Columns.Add(SystemManager.mStringResource.GetText(StringResource.TextType.Collection_Status_IsCapped));
lstData.Columns.Add(SystemManager.mStringResource.GetText(StringResource.TextType.Collection_Status_MaxDocuments));
lstData.Columns.Add(SystemManager.mStringResource.GetText(StringResource.TextType.Collection_Status_AverageObjectSize));
lstData.Columns.Add(SystemManager.mStringResource.GetText(StringResource.TextType.Collection_Status_PaddingFactor));
}
foreach (String mongoSvrKey in _mongoConnSvrLst.Keys)
{
try
{
MongoServer mongoSvr = _mongoConnSvrLst[mongoSvrKey];
//感谢 魏琼东 的Bug信息,一些命令必须以Admin执行
if (!SystemManager.GetCurrentServerConfig(mongoSvrKey).Health ||
!SystemManager.GetCurrentServerConfig(mongoSvrKey).LoginAsAdmin) { continue; }
List<String> databaseNameList = mongoSvr.GetDatabaseNames().ToList<String>();
foreach (String strDBName in databaseNameList)
{
MongoDatabase mongoDB = mongoSvr.GetDatabase(strDBName);
List<String> colNameList = mongoDB.GetCollectionNames().ToList<String>();
foreach (String strColName in colNameList)
{
try
{
CollectionStatsResult CollectionStatus = mongoDB.GetCollection(strColName).GetStats();
ListViewItem lst = new ListViewItem(mongoSvrKey + "." + strDBName + "." + strColName);
lst.SubItems.Add(CollectionStatus.ObjectCount.ToString());
lst.SubItems.Add(GetSize(CollectionStatus.DataSize));
lst.SubItems.Add(GetSize(CollectionStatus.LastExtentSize));
lst.SubItems.Add(GetSize(CollectionStatus.StorageSize));
lst.SubItems.Add(GetSize(CollectionStatus.TotalIndexSize));
//2012-3-6
lst.SubItems.Add(CollectionStatus.IsCapped.ToString());
//https://jira.mongodb.org/browse/CSHARP-665
try
{
//注意:这个MaxDocuments只是在CappedCollection时候有效
lst.SubItems.Add(CollectionStatus.MaxDocuments.ToString());
}
catch (Exception ex)
{
//溢出
lst.SubItems.Add(Int32.MaxValue.ToString());
SystemManager.ExceptionLog(ex);
}
if (CollectionStatus.ObjectCount != 0)
{
//在某些条件下,这个值会抛出异常,IndexKeyNotFound
//同时发现,这个时候Count = 0,TryCatch可能会消耗时间,所以改为条件判断
lst.SubItems.Add(GetSize((long)CollectionStatus.AverageObjectSize));
}
else
{
lst.SubItems.Add("0");
}
try
{
//在某些条件下,这个值会抛出异常,IndexKeyNotFound
lst.SubItems.Add(CollectionStatus.PaddingFactor.ToString());
}
catch (Exception)
{
lst.SubItems.Add("0");
}
lstData.Items.Add(lst);
}
catch (Exception ex)
{
//throw;
//TODO:排序时候会发生错误,所以暂时不对应
//lstData.Items.Add(new ListViewItem(strColName + "[Exception]"));
SystemManager.ExceptionDeal(ex);
}
}
}
}
catch (Exception ex)
{
SystemManager.ExceptionDeal(ex);
}
}
lstData.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize);
}
示例15: FillCurrentOprToList
/// <summary>
/// 将数据Opr放入ListView
/// </summary>
/// <param name="lstSrvOpr"></param>
public static void FillCurrentOprToList(ListView lstSrvOpr)
{
lstSrvOpr.Clear();
lstSrvOpr.Columns.Add("Name");
lstSrvOpr.Columns.Add("opid");
lstSrvOpr.Columns.Add("active");
lstSrvOpr.Columns.Add("lockType");
lstSrvOpr.Columns.Add("waitingForLock");
lstSrvOpr.Columns.Add("secs_running");
lstSrvOpr.Columns.Add("op");
lstSrvOpr.Columns.Add("ns");
lstSrvOpr.Columns.Add("query");
lstSrvOpr.Columns.Add("client");
lstSrvOpr.Columns.Add("desc");
lstSrvOpr.Columns.Add("connectionId");
lstSrvOpr.Columns.Add("numYields");
foreach (String mongoSvrKey in _mongoConnSvrLst.Keys)
{
try
{
MongoServer mongoSvr = _mongoConnSvrLst[mongoSvrKey];
//感谢 魏琼东 的Bug信息,一些命令必须以Admin执行
if (!SystemManager.GetCurrentServerConfig(mongoSvrKey).Health ||
!SystemManager.GetCurrentServerConfig(mongoSvrKey).LoginAsAdmin) { continue; }
List<String> databaseNameList = mongoSvr.GetDatabaseNames().ToList<String>();
foreach (String strDBName in databaseNameList)
{
try
{
MongoDatabase mongoDB = mongoSvr.GetDatabase(strDBName);
BsonDocument dbStatus = mongoDB.GetCurrentOp();
BsonArray doc = dbStatus.GetValue("inprog").AsBsonArray;
foreach (BsonDocument item in doc)
{
ListViewItem lst = new ListViewItem(mongoSvrKey + "." + strDBName);
foreach (String itemName in item.Names)
{
lst.SubItems.Add(item.GetValue(itemName).ToString());
}
lstSrvOpr.Items.Add(lst);
}
}
catch (Exception ex)
{
SystemManager.ExceptionDeal(ex);
}
}
}
catch (Exception ex)
{
SystemManager.ExceptionDeal(ex);
}
}
lstSrvOpr.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize);
}