在Dialog中显示列表视图 [英] Display listview in Dialog

查看:80
本文介绍了在Dialog中显示列表视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





i希望在我的应用程序中显示listview项目。



当用户输入ID时在txtbox中按Enter键,想在列表视图中显示结果。



i需要在Dialog中显示列表,如(消息框)

Hi

i want to display listview items in my application .

when the user put ID in the txtbox and press Enter , want to display the result in list view .

i need to display the list in Dialog like ( message box )

推荐答案

没有开箱即用的解决方案,但你可以轻松完成。



创建一个表单,添加一个ListView。

在你的主窗体上显示一个Dialog,如下所示:

There isn't a "out of the box" solution for this, but you can do it easy.

Create a form, add a ListView.
On your main form show a Dialog, something like this:
using (var f = new FormList(id))
{
    if (f.ShowDialog() == DialogResult.OK)
    {
        MessageBox.Show(f.Result);
    }
}


使用此代码



use this code

public static DialogResult ShowMe(string title, string promptText, ref string value)
       {
           //'value' is to return Some value
           Form form = new Form();
           Label label = new Label();
           ListView lv = new ListView();

           System.Windows.Forms.Button buttonOk = new System.Windows.Forms.Button();
           System.Windows.Forms.Button buttonCancel = new System.Windows.Forms.Button();

           form.Text = title;
           label.Text = "Some heading";

           buttonOk.Text = "OK";
           buttonCancel.Text = "Cancel";
           buttonOk.DialogResult = DialogResult.OK;
           buttonCancel.DialogResult = DialogResult.Cancel;

           label.SetBounds(9, 20, 372, 13);
           lv.SetBounds(9, 40, 280, 66);


           buttonOk.SetBounds(228, 110, 75, 23);
           buttonCancel.SetBounds(309, 110, 75, 23);

           label.AutoSize = true;

           buttonOk.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
           buttonCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;

           form.ClientSize = new Size(396, 150);
           form.Controls.AddRange(new Control[] { label,lv,  buttonOk, buttonCancel });
           form.ClientSize = new Size(Math.Max(300, label.Right + 10), form.ClientSize.Height);
           form.FormBorderStyle = FormBorderStyle.FixedDialog;
           form.StartPosition = FormStartPosition.CenterScreen;
           form.MinimizeBox = false;
           form.MaximizeBox = false;
           form.AcceptButton = buttonOk;
           form.CancelButton = buttonCancel;

           DialogResult dialogResult = form.ShowDialog();
           return dialogResult;
       }


这篇关于在Dialog中显示列表视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆