Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

Am retrieve the queue message from my MSMQ and populate in List view but i want to put it in a nicer way like

eg:
S.NO Queue Message
1 Message


But my current code just populate all the message ,is this any please guide me on the right track to achieve like the above eg.

C#
private void button8_Click(object sender, EventArgs e)
        {
            System.Messaging.Message mes;
            string m;
            try
            {
                listBox1.Items.Clear();
                int len = mq.GetAllMessages().Length;
                if (len != 0)
                {
                    for (int i = 0; i < len; i++)
                    {
                        mes = mq.Receive(new TimeSpan(0, 0, 3));
                        mes.Formatter = new XmlMessageFormatter(new string[] { "System.String,mscorlib" });
                        m = mes.Body.ToString();
                         ListViewItem item1 = new ListViewItem(m.ToString());
                        item1.SubItems.Add(m.ToString());
                       listView1.Items.AddRange(new ListViewItem[] { item1});
                    }
                }
                else
                {
                    m = "No Error Queue Message";
                      ListViewItem item1 = new ListViewItem(m.ToString());
                        item1.SubItems.Add(m.ToString());
                       listView1.Items.AddRange(new ListViewItem[] { item1});
                }

            }
            catch
            {
                m = "no Message";
                  ListViewItem item1 = new ListViewItem(m.ToString());
                        item1.SubItems.Add(m.ToString());
                       listView1.Items.AddRange(new ListViewItem[] { item1});
            }
            
        }
Posted
Updated 3-Aug-11 17:57pm
v3

1 solution

Set View property to Details
Add columns as,
C#
ListView1.Columns.Add("No");
ListView1.Columns.Add("Name");

Add rows as,
C#
ListView1.Items.Add(new ListViewItem(new string[] { "1", "Message" } );
 
Share this answer
 
v3
Comments
shan1395 4-Aug-11 0:11am    
Thanks Prerak,

But i want to display my items like

column name : ID Column Name : Message
1 Sample Message (i will get this from m.tostring())

as per your input am not getting the column name and adding the rows vice
Prerak Patel 4-Aug-11 0:14am    
I couldn't get you.
BTW I have updated the answer. Check if that helps.
shan1395 4-Aug-11 0:29am    
i was exactly follow you here is the modified code

listView1.Columns.Add("No");
listView1.Columns.Add("MSMQ message");
listView1.Items.Add(new ListViewItem(new string[] { "1", m.ToString() }));


I suppose to get like

No MSMQ Message
1 testMessage

But wat am getting here in my listview is

1 1 1 1 1

it has 5 MSMQ message but it just populated the constant value.

Eventhough it populated in column it should be

NO MSMQ Message
1 TestMessage1
1 TestMessage2
1 TestMessage3
1 TestMessage4
Prerak Patel 4-Aug-11 0:37am    
You have not set the View property to Details. Go to designer and set. Or ListView1.View=View.Details
shan1395 4-Aug-11 0:45am    
Awesome Prerak patel .

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