Click here to Skip to main content
15,892,575 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello All,
I was trying to populate my my datagridview column.But am not sure how i have to fill the static column.am doing the same thing in Listview it works fine but when i replace with datagridview am not sure where i missed.
Here is my code so far.

C#
 private void button9_Click(object sender, EventArgs e)
        {
            //int n = dataGridView1.Rows.Add();

            //dataGridView1.Rows[n].Cells[0].Value = "title";
            System.Messaging.Message mes;
            string m;
            int n = dataGridView1.Rows.Add();
          
            try
            {
               
                
                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();
                    // listView1.Items.Add(new ListViewItem(new string[] {"1" ,"1234","BusList","TRS" ,m.ToString(), }));
//Am trying to do the samething for my datagridview.
                       dataGridView1.Rows[n].Cells[0].Value = m.ToString();
                        //   listBox1.Items.Add(m.ToString());

                    }
                }
                else
                {
                    //listView1.Items.Clear();
                    dataGridView1.ClearSelection();
                    m = "No Error Queue Message";
                    //listView1.Items.Add(m.ToString());
                    dataGridView1.Rows[n].Cells[0].Value = m.ToString();
                    
                    
                }

            }
            catch
            {
                m = "no Message";
                //listView1.Items.Add(m.ToString());
                dataGridView1.Rows[n].Cells[0].Value = m.ToString();
            }


What am trying to acheive here is am getting Queue from my MSMQ and popluate in the grid so far am getting only one message but its not looping.
Posted
Updated 8-Aug-11 17:55pm
v4

1 solution

Hello,

do you have added a column to the datagridview in the designer?
If not add a column with the designer or this code (for example in formaload)
C#
datagridview1.Columns.Add("Message");


then you cann add rows in your loop like this:
C#
datagridview1.Rows.Add(m.ToString());


I hope this might help you.
 
Share this answer
 
Comments
shan1395 10-Aug-11 3:13am    
Thanks Thomas, i just followed this example

ErrGrid.Rows[n].Cells[5].Value = m.ToString();

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