本文整理汇总了C#中System.Windows.Forms.ListView.EnsureVisible方法的典型用法代码示例。如果您正苦于以下问题:C# ListView.EnsureVisible方法的具体用法?C# ListView.EnsureVisible怎么用?C# ListView.EnsureVisible使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Forms.ListView
的用法示例。
在下文中一共展示了ListView.EnsureVisible方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddListViewData
//添加单行数据
public void AddListViewData(ListView list, Dictionary<string, string> data)
{
if (list.InvokeRequired)//不能访问就创建委托
{
ListViewDelegate d = new ListViewDelegate(AddListViewData);
list.Invoke(d, new object[] { list, data });
}
else
{
list.BeginUpdate();
ListViewItem list_item = new ListViewItem();
bool need_init = true;
foreach (KeyValuePair<string, string> cell in data)
{
ListViewItem.ListViewSubItem list_sub_item = new ListViewItem.ListViewSubItem();
if (need_init)
{
list_item.Text = cell.Value;
need_init = false;
}
else
{
list_sub_item.Text = cell.Value;
list_item.SubItems.Add(list_sub_item);
}
}
list.Items.Add(list_item);
list.EnsureVisible(list.Items.Count - 1);
list.EndUpdate();
}
}
示例2: 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]);
}
示例3: ListViewBuilder
public void ListViewBuilder(ListView listView, Color? color = null, int columnFullWidth = 99, params string[] value)
{
listView.Items.Add(new ListViewItem(value));
if (color != null)
{
listView.Items[listView.Items.Count - 1].ForeColor = (Color)color;
}
listView.EnsureVisible(listView.Items.Count - 1);
ListViewResizeColumn(listView, columnFullWidth);
}
示例4: SelectListItem
public static void SelectListItem(ListView lst, int index)
{
if (lst.Items.Count > 0)
{
foreach (ListViewItem v in lst.Items)
{
if (v.Index == index)
{
v.Focused = true;
v.Selected = true;
lst.EnsureVisible(index);
break;
}
}
}
}
示例5: doEnsureVisible
private void doEnsureVisible(ListView listView, ListViewItem item)
{
int index = listView.Items.IndexOf(item);
if (index < 0) return;
if (listView.Items.Count > index + 2)
listView.EnsureVisible(index + 2);
else if (listView.Items.Count > index + 1)
listView.EnsureVisible(index + 1);
else
listView.EnsureVisible(index);
}
示例6: FindFirstInProductList
private static bool FindFirstInProductList(ListView list, ProductSearchSettings settings)
{
foreach (ListViewItem lvi in list.Items) lvi.Selected = false;
if (settings.SearchStartingRow >= list.Items.Count)
return false;
for (int i = settings.SearchStartingRow; i < list.Items.Count; i++)
{
ListViewItem lvi = list.Items[i];
if (FindInItem(lvi, settings))
{
lvi.Selected = true;
settings.SearchStartingRow = i + 1;
list.EnsureVisible(i);
return true;
}
}
return false;
}
示例7: SynchronizeCursor
private static void SynchronizeCursor(ListView first, ListView second)
{
if (first.SelectedIndices.Count > 0)
{
int index = first.SelectedIndices[0];
if (index < second.Items.Count)
{
second.SelectedIndices.Add(index);
second.EnsureVisible(index);
}
}
}
示例8: LoadOneItem
// 根据册条码号或者记录路径,装入册记录
// parameters:
// strBarcodeOrRecPath 册条码号或者记录路径。如果内容前缀为"@path:"则表示为路径
// strMatchLocation 附加的馆藏地点匹配条件。如果==null,表示没有这个附加条件(注意,""和null含义不同,""表示确实要匹配这个值)
// return:
// -2 册条码号或者记录路径已经在list中存在了(行没有加入listview中)
// -1 出错(注意表示出错的行已经加入listview中了)
// 0 因为馆藏地点不匹配,没有加入list中
// 1 成功
int LoadOneItem(
string strPubType,
string strBarcodeOrRecPath,
RecordInfo info,
ListView list,
string strMatchLocation,
out string strOutputItemRecPath,
ref ListViewItem item,
out string strError)
{
strError = "";
strOutputItemRecPath = "";
long lRet = 0;
// 判断是否有 @path: 前缀,便于后面分支处理
bool bIsRecPath = StringUtil.HasHead(strBarcodeOrRecPath, "@path:");
string strItemText = "";
string strBiblioText = "";
// string strItemRecPath = "";
string strBiblioRecPath = "";
XmlDocument item_dom = null;
string strBiblioSummary = "";
string strISBnISSN = "";
if (info == null)
{
byte[] item_timestamp = null;
REDO_GETITEMINFO:
lRet = Channel.GetItemInfo(
stop,
strBarcodeOrRecPath,
"xml",
out strItemText,
out strOutputItemRecPath,
out item_timestamp,
"recpath",
out strBiblioText,
out strBiblioRecPath,
out strError);
if (lRet == -1)
{
DialogResult temp_result = MessageBox.Show(this,
strError + "\r\n\r\n是否重试?",
"AccountBookForm",
MessageBoxButtons.RetryCancel,
MessageBoxIcon.Question,
MessageBoxDefaultButton.Button1);
if (temp_result == DialogResult.Retry)
goto REDO_GETITEMINFO;
}
if (lRet == -1 || lRet == 0)
{
#if NO
if (item == null)
{
item = new ListViewItem(strBarcodeOrRecPath, 0);
list.Items.Add(item);
}
else
{
Debug.Assert(item.ListView == list, "");
}
// item.SubItems.Add(strError);
ListViewUtil.ChangeItemText(item, COLUMN_ERRORINFO, strError);
SetItemColor(item, TYPE_ERROR);
// 将新加入的事项滚入视野
list.EnsureVisible(list.Items.IndexOf(item));
#endif
SetError(list,
ref item,
strBarcodeOrRecPath,
strError);
goto ERROR1;
}
SummaryInfo summary = (SummaryInfo)this.m_summaryTable[strBiblioRecPath];
if (summary != null)
{
strBiblioSummary = summary.Summary;
strISBnISSN = summary.ISBnISSn;
}
if (strBiblioSummary == ""
&& this.checkBox_load_fillBiblioSummary.Checked == true)
{
//.........这里部分代码省略.........
示例9: SetError
internal override void SetError(ListView list,
ref ListViewItem item,
string strBarcodeOrRecPath,
string strError)
{
// 确保线程安全 2014/9/3
if (list != null && list.InvokeRequired)
{
Delegate_SetError d = new Delegate_SetError(SetError);
object[] args = new object[4];
args[0] = list;
args[1] = item;
args[2] = strBarcodeOrRecPath;
args[3] = strError;
this.Invoke(d, args);
// 取出 ref 参数值
item = (ListViewItem)args[1];
return;
}
if (item == null)
{
item = new ListViewItem(strBarcodeOrRecPath, 0);
list.Items.Add(item);
}
else
{
Debug.Assert(item.ListView == list, "");
}
// item.SubItems.Add(strError);
ListViewUtil.ChangeItemText(item, COLUMN_ERRORINFO, strError);
SetItemColor(item, TYPE_ERROR);
// 将新加入的事项滚入视野
list.EnsureVisible(list.Items.IndexOf(item));
}
示例10: LoadOneItem
// 根据册条码号或者记录路径,装入册记录
// parameters:
// strBarcodeOrRecPath 册条码号或者记录路径。如果内容前缀为"@path:"则表示为路径
// strMatchLocation 附加的馆藏地点匹配条件。如果==null,表示没有这个附加条件(注意,""和null含义不同,""表示确实要匹配这个值)
// return:
// -2 册条码号已经在list中存在了(行没有加入listview中)
// -1 出错(注意表示出错的行已经加入listview中了)
// 0 因为馆藏地点不匹配,没有加入list中
// 1 成功
public int LoadOneItem(
string strBarcodeOrRecPath,
ListView list,
string strMatchLocation,
out string strError)
{
strError = "";
// 判断是否有 @path: 前缀,便于后面分支处理
bool bIsRecPath = StringUtil.HasHead(strBarcodeOrRecPath, "@path:"); ;
string strItemXml = "";
string strBiblioText = "";
string strItemRecPath = "";
string strBiblioRecPath = "";
byte[] item_timestamp = null;
long lRet = Channel.GetItemInfo(
stop,
strBarcodeOrRecPath,
"xml",
out strItemXml,
out strItemRecPath,
out item_timestamp,
"recpath",
out strBiblioText,
out strBiblioRecPath,
out strError);
if (lRet == -1 || lRet == 0)
{
ListViewItem item = null;
if (bIsRecPath == false)
item = new ListViewItem(strBarcodeOrRecPath, 0);
else
item = new ListViewItem("", 0); // 暂时还没有办法知道条码
// 2009/10/29
OriginItemData data = new OriginItemData();
item.Tag = data;
data.Timestamp = item_timestamp;
data.Xml = strItemXml;
ListViewUtil.ChangeItemText(item,
COLUMN_ERRORINFO,
strError);
// item.SubItems.Add(strError);
SetItemColor(item, TYPE_ERROR);
list.Items.Add(item);
// 将新加入的事项滚入视野
list.EnsureVisible(list.Items.Count - 1);
goto ERROR1;
}
string strBiblioSummary = "";
string strISBnISSN = "";
string strTargetRecPath = "";
// 看看册条码号是否有重复?
// 顺便获得同种的事项
for (int i = 0; i < list.Items.Count; i++)
{
ListViewItem curitem = list.Items[i];
if (bIsRecPath == false)
{
if (strBarcodeOrRecPath == curitem.Text)
{
strError = "册条码号 " + strBarcodeOrRecPath + " 发生重复";
return -2;
}
}
else
{
if (strBarcodeOrRecPath == ListViewUtil.GetItemText(curitem, COLUMN_RECPATH))
{
strError = "记录路径 " + strBarcodeOrRecPath + " 发生重复";
return -2;
}
}
if (strBiblioSummary == "" && curitem.ImageIndex != TYPE_ERROR)
{
if (curitem.SubItems[COLUMN_BIBLIORECPATH].Text == strBiblioRecPath)
{
strBiblioSummary = ListViewUtil.GetItemText(curitem, COLUMN_SUMMARY);
//.........这里部分代码省略.........
示例11: LoadOneItem
//.........这里部分代码省略.........
strBarcodeOrRecPath = "@path:" + info.Record.Path;
bIsRecPath = true;
if (info.Record.RecordBody.Result.ErrorCode != ErrorCodeValue.NoError)
{
SetError(list,
ref item,
strBarcodeOrRecPath,
info.Record.RecordBody.Result.ErrorString);
goto ERROR1;
}
strItemText = info.Record.RecordBody.Xml;
strOutputItemRecPath = info.Record.Path;
// 2013/4/3
if (info.Record.RecordBody != null)
item_timestamp = info.Record.RecordBody.Timestamp;
//
item_dom = info.Dom;
strBiblioRecPath = info.BiblioRecPath;
if (info.SummaryInfo != null)
{
#if NO
strBiblioSummary = info.SummaryInfo.Summary;
strISBnISSN = info.SummaryInfo.ISBnISSn;
#endif
summary = info.SummaryInfo;
}
}
// 附加的馆藏地点匹配
if (strMatchLocation != null)
{
// TODO: #reservation, 情况如何处理?
string strLocation = DomUtil.GetElementText(item_dom.DocumentElement,
"location");
// 2013/3/26
if (strLocation == null)
strLocation = "";
if (strMatchLocation != strLocation)
return 0;
}
if (item == null)
{
item = AddToListView(list,
item_dom,
item_timestamp,
strOutputItemRecPath,
strBiblioRecPath,
#if NO
strBiblioSummary,
strISBnISSN,
#endif
summary_col_names,
summary);
// 将新加入的事项滚入视野
list.EnsureVisible(list.Items.Count - 1);
#if NO
// 填充需要从订购库获得的栏目信息
if (this.checkBox_load_fillOrderInfo.Checked == true)
FillOrderColumns(item, strPubType);
#endif
}
else
{
SetListViewItemText(item_dom,
item_timestamp,
true,
strOutputItemRecPath,
strBiblioRecPath,
#if NO
strBiblioSummary,
strISBnISSN,
#endif
summary_col_names,
summary,
item);
}
int nRet = VerifyItem(
strPubType,
strBarcodeOrRecPath,
item,
item_dom,
out strError);
if (nRet == -1)
goto ERROR1;
return 1;
ERROR1:
return -1;
}
示例12: DownloadSpoiler
public void DownloadSpoiler(XmlDocument xSet, XmlDocument xSetLang, ListView list, ProgressBar progressBar)
{
mList = list;
ListViewItem item;
if(Directory.Exists("cards"))
Directory.Delete("cards", true);
Directory.CreateDirectory("cards");
foreach(XmlNode nodeSet in xSet.DocumentElement.SelectNodes("card_sets/item"))
{
string setCode = nodeSet.Attributes["code"].Value;
string setName = xSetLang.DocumentElement.SelectSingleNode("card_sets_lang/item[@code='" + setCode + "' and @language='ENG']/@name").InnerText;
if(setCode != "M12")
continue;
string cardsPath = "cards\\" + setCode + ".xml";
string cardsLangPath = "cards\\" + setCode + ".eng.xml";
if(File.Exists(cardsPath))
File.Delete(cardsPath);
if(File.Exists(cardsLangPath))
File.Delete(cardsLangPath);
XmlDocument xCards = new XmlDocument();
xCards.LoadXml("<cards />");
XmlDocument xCardsLang = new XmlDocument();
xCardsLang.LoadXml("<cards />");
DateTime setDate = XmlConvert.ToDateTime(nodeSet.Attributes["releaseDate"].Value, "yyyy-MM-ddTHH:mm:ss");
xCards.DocumentElement.Attributes.Append(xCards.CreateAttribute("releaseDate")).Value = setDate.ToString("yyyy-MM-ddTHH:mm:ss");
xCards.DocumentElement.Attributes.Append(xCards.CreateAttribute("code")).Value = setCode;
xCardsLang.DocumentElement.Attributes.Append(xCardsLang.CreateAttribute("name")).Value = setName;
string contentTextPath = Path.Combine(Path.Combine(CARDS_DIRPATH, setCode), "CONTENT.txt");
string contentXmlPath = Path.Combine(Path.Combine(CARDS_DIRPATH, setCode), "CONTENT.xml");
string listPath = Path.Combine(Path.Combine(CARDS_DIRPATH, setCode), "list.xml");
item = new ListViewItem(setCode);
ListViewItem.ListViewSubItem subItem = item.SubItems.Add("Working...");
mList.Items.Add(item);
mList.EnsureVisible(mList.Items.Count - 1);
Application.DoEvents();
progressBar.Minimum = 0;
progressBar.Step = 1;
progressBar.Value = 0;
XmlDocument xCardList = new XmlDocument();
xCardList.Load(listPath);
XmlDocument xContent = new XmlDocument();
string allContent;
if(!File.Exists(contentTextPath))
{
// download page content
subItem.Text = "Downloading...";
mList.FindForm().Refresh();
Application.DoEvents();
allContent = string.Empty;
xContent.LoadXml("<content />");
progressBar.Maximum = xCardList.SelectNodes("//card").Count;
foreach(XmlNode cardNode in xCardList.SelectNodes("//card"))
{
string id = cardNode.SelectSingleNode("@id").InnerText;
string content = Download(URL_SPOILER + id);
allContent += content;
XmlNode nodeContent = xContent.ImportNode(GetDocument(content).DocumentElement, true);
xContent.DocumentElement.AppendChild(nodeContent);
progressBar.PerformStep();
mList.FindForm().Refresh();
Application.DoEvents();
}
File.WriteAllText(contentTextPath, allContent);
xContent.Save(contentXmlPath);
subItem.Text = "OK!";
mList.FindForm().Refresh();
Application.DoEvents();
}
subItem.Text = "Creating...";
mList.FindForm().Refresh();
Application.DoEvents();
xContent.Load(contentXmlPath);
progressBar.Value = 0;
progressBar.Maximum = xContent.DocumentElement.SelectNodes("td").Count;
XmlNodeList cardListNodes = xCardList.DocumentElement.SelectNodes("card");
XmlNodeList contentNodes = xContent.DocumentElement.SelectNodes("td");
for(int i = 0; i < cardListNodes.Count; i++)
{
SpoilerReader spoilerReader = new SpoilerReader(cardListNodes[i].SelectSingleNode("@name").InnerText,
cardListNodes[i].SelectSingleNode("@color").InnerText);
spoilerReader.CreateCardNode(contentNodes[i], xCards, xCardsLang, setCode, setDate, i + 1);
progressBar.PerformStep();
mList.FindForm().Refresh();
Application.DoEvents();
}
//.........这里部分代码省略.........
示例13: UpdateFileListFiltered
private static void UpdateFileListFiltered(ListView listView, IEnumerable<ListViewItem> items, string filter)
{
var selection = new Pair<ListViewItem, int>();
foreach (var item in items)
{
item.Selected = false;
var filterPos =
item.Text.IndexOf(
filter,
StringComparison.CurrentCultureIgnoreCase);
if (filterPos < 0)
continue;
if (selection.First == null)
selection = new Pair<ListViewItem, int>(item, filterPos);
else if ((filterPos == 0) && (selection.Second != 0))
selection = new Pair<ListViewItem, int>(item, filterPos);
listView.Items.Add(item);
}
if (selection.First == null)
return;
selection.First.Selected = true;
listView.EnsureVisible(selection.First.Index);
}
示例14: SetError
internal override void SetError(ListView list,
ref ListViewItem item,
string strBarcodeOrRecPath,
string strError)
{
if (item == null)
{
item = new ListViewItem(strBarcodeOrRecPath, 0);
list.Items.Add(item);
}
else
{
Debug.Assert(item.ListView == list, "");
}
// item.SubItems.Add(strError);
ListViewUtil.ChangeItemText(item, COLUMN_ERRORINFO, strError);
SetItemColor(item, TYPE_ERROR);
// 将新加入的事项滚入视野
list.EnsureVisible(list.Items.IndexOf(item));
}
示例15: AddKeyToScript
private void AddKeyToScript(ListView listview)
{
if (m_selectedKey == null) return;
listview.Items.Add((ListViewItem)m_selectedKey.Clone());
listview.EnsureVisible(listview.Items.Count - 1);
AutoCheckValidity();
}