Click here to Skip to main content
15,889,858 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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 )
Posted

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);
    }
}
 
Share this answer
 
v2
use this code

C#
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;
       }
 
Share this answer
 
Comments
Jean A Brandelero 12-Sep-13 12:48pm    
Nice solution! haha.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900