填写“静态数据网格视图"列 [英] Fill the Static Datagrid View columns

查看:54
本文介绍了填写“静态数据网格视图"列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
我试图填充我的datagridview列.但是不确定我如何填充静态column.am在Listview中做同样的事情,它可以正常工作,但是当我用datagridview替换时,我不确定我错过了哪里.
到目前为止,这是我的代码.

 私有 无效 button9_Click(对象发​​件人,EventArgs e)
        {
            //  int n = dataGridView1.Rows.Add(); 

            //  dataGridView1.Rows [n] .Cells [0] .Value ="title"; 
            System.Messaging.Message mes;
            字符串 m;
             int  n = dataGridView1.Rows.Add();
          
            尝试
            {
               
                
                 int  len = mq.GetAllMessages().Length;
                
                如果(len!=  0 )
                {
                     for ( int  i =  0 ; i <  len; i ++)
                    {
                        mes = mq.Receive( TimeSpan( 0  0  3 ));
                        mes.Formatter =  XmlMessageFormatter( 字符串 [] {" });
                        m = mes.Body.ToString();
                    //  listView1.Items.Add(new ListViewItem(new string [] {"1","1234","BusList ," TRS,m.ToString(),})); 
// 我正试图为我的datagridview做同样的事情.
                       dataGridView1.Rows [n] .Cells [ 0 ].Value = m.ToString();
                        //  listBox1.Items.Add(m.ToString()); 

                    }
                }
                其他
                {
                    //  listView1.Items.Clear(); 
                    dataGridView1.ClearSelection();
                    m = " //  listView1.Items.Add(m.ToString()); 
                    dataGridView1.Rows [n] .Cells [ 0 ].Value = m.ToString();
                    
                    
                }

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



在这里要达到的目的是从我的MSMQ获取Queue,并在网格中填充到目前为止,仅收到一条消息,但没有循环.

解决方案

您好,

您是否已在设计器的datagridview中添加一列?
如果没有,请添加带有设计器或此代码的列(例如,在formaload中)

 datagridview1.Columns.Add(" );  

那么您就不能像这样在循环中添加行:

 datagridview1.Rows.Add(m.ToString()); 



希望对您有所帮助.


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.

 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.

解决方案

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)

datagridview1.Columns.Add("Message");



then you cann add rows in your loop like this:

datagridview1.Rows.Add(m.ToString());



I hope this might help you.


这篇关于填写“静态数据网格视图"列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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