Пример #1
0
        private void button_new_Click(object sender, EventArgs e)
        {
            EntityDialog dlg = new EntityDialog();

            dlg.ShowDialog(this);

            if (dlg.DialogResult == System.Windows.Forms.DialogResult.Cancel)
            {
                return;
            }

            ListViewItem item = new ListViewItem();

            SetListViewItem(item, dlg.Entity);
            this.listView_entities.Items.Add(item);

            this.listView_entities.SelectedIndices.Clear();
            ListViewUtil.BeginSelectItem(this.listView_entities, item);
        }
Пример #2
0
        void FillList(bool bAutoSelect)
        {
            // 2015/6/14
            string strExistName = this.textBox_name.Text;

            listView1.Items.Clear();
            listView1_SelectedIndexChanged(null, null);

            bool        bSelected = false;
            XmlNodeList nodes     = dom.DocumentElement.SelectNodes("template");

            for (int i = 0; i < nodes.Count; i++)
            {
                string strName    = DomUtil.GetAttr(nodes[i], "name");
                string strComment = DomUtil.GetAttr(nodes[i], "comment");

                ListViewItem item = new ListViewItem(strName, 0);
                item.SubItems.Add(strComment);

                listView1.Items.Add(item);

                if (bAutoSelect == true &&
                    string.IsNullOrEmpty(strExistName) == false &&
                    strName == strExistName)
                {
                    bSelected = true;
                    ListViewUtil.BeginSelectItem(this, item);
                }
            }

            if (bAutoSelect == true && bSelected == false)
            {
                // 选择第一项
                if (listView1.Items.Count != 0)
                {
                    ListViewUtil.BeginSelectItem(this, listView1.Items[0]);
                }
            }
        }