C# dataGridView 顯示圖形+文字

C# dataGridView 顯示圖形+文字

C# dataGridView 顯示圖形+文字



資料來源:http://tablegridview.blogspot.tw/


code

        public void showControllersData()
        {
            if (m_Controller.getController() == 0)
            {
                m_intTimerStep = 0;//重新登錄狀態
            }
            //MessageBox.Show(m_Controller.m_StrGetData);
            dataGridView_Controller1.Columns.Clear();
            dataGridView_Controller1.ColumnHeadersDefaultCellStyle.Font = new Font("Tahoma", 10);//欄位字體//https://vectus.wordpress.com/2011/03/20/datagridview-cell-%E5%8F%8A-header-%E5%AD%97%E5%9E%8B-%E5%8F%8A-%E5%A4%A7%E5%B0%8F-%E6%8E%A7%E5%88%B6/
            //https://msdn.microsoft.com/zh-tw/library/z2akwyy7(v=vs.110).aspx
            dataGridView_Controller1.DefaultCellStyle.Font = new Font("Tahoma", 10);
            dataGridView_Controller1.DefaultCellStyle.ForeColor = Color.Blue;
            dataGridView_Controller1.DefaultCellStyle.BackColor = Color.Beige;
            //https://msdn.microsoft.com/zh-tw/library/system.windows.forms.datagridviewbuttoncell(v=vs.110).aspx
            dataGridView_Controller1.ReadOnly = true;//禁止編輯
            dataGridView_Controller1.AllowUserToAddRows = false;//刪除空白列//http://www.programmer-club.com.tw/showSameTitleN/csharp/5354.html
            
            DataTable dt1 = new DataTable();
            dt1.Columns.Add(m_StrMsg_GridView00, typeof(Image));
            dt1.Columns.Add(m_StrMsg_GridView01);
            dt1.Columns.Add(m_StrMsg_GridView02);
            dt1.Columns.Add(m_StrMsg_GridView03);
            dt1.Columns.Add(m_StrMsg_GridView05);
            dt1.Columns.Add(m_StrMsg_GridView06);
            dt1.Columns.Add(m_StrMsg_GridView07);

            for (int i = 0; i < m_Controller.m_ListControllers.Count; i++)
            {
                String StrBuf="0";
                if(m_Controller.m_ListControllers[i].connection_failed_timestamp>0)
                {
                    System.DateTime dt = new System.DateTime(2000, 1, 1).AddSeconds(m_Controller.m_ListControllers[i].connection_failed_timestamp);
                    StrBuf=dt.ToString("yyyy/MM/dd HH:mm:ss");
                }

                string photopath = Application.StartupPath + @"\images\";

                if ((m_Controller.m_ListControllers[i].status == 1)||(m_Controller.m_ListControllers[i].status == 8))
                {
                    //string[] row = new string[] { ("Online:" + m_Controller.m_ListControllers[i].status), ("" + m_Controller.m_ListControllers[i].identifier), m_Controller.m_ListControllers[i].name, m_Controller.m_ListControllers[i].model_type,m_Controller.m_ListControllers[i].serial_number, m_Controller.m_ListControllers[i].connection_parameter, "" + m_Controller.m_ListControllers[i].connection_failed_counter, "" + StrBuf };
                    dt1.Rows.Add(Image.FromFile(photopath + "gball.png"), ("" + m_Controller.m_ListControllers[i].identifier), m_Controller.m_ListControllers[i].name, m_Controller.m_ListControllers[i].model_type, m_Controller.m_ListControllers[i].connection_parameter, ("" + m_Controller.m_ListControllers[i].connection_failed_counter), ("" + StrBuf));////http://tablegridview.blogspot.tw/
                }
                else
                {
                    //string[] row = new string[] { ("Offline:" + m_Controller.m_ListControllers[i].status), ("" + m_Controller.m_ListControllers[i].identifier), m_Controller.m_ListControllers[i].name, m_Controller.m_ListControllers[i].model_type,m_Controller.m_ListControllers[i].serial_number, m_Controller.m_ListControllers[i].connection_parameter, "" + m_Controller.m_ListControllers[i].connection_failed_counter, "" + StrBuf };
                    dt1.Rows.Add(Image.FromFile(photopath + "rball.png"), ("" + m_Controller.m_ListControllers[i].identifier), m_Controller.m_ListControllers[i].name, m_Controller.m_ListControllers[i].model_type, m_Controller.m_ListControllers[i].connection_parameter, ("" + m_Controller.m_ListControllers[i].connection_failed_counter), ("" + StrBuf));//http://tablegridview.blogspot.tw/
                }
            }
            dataGridView_Controller1.DataSource = dt1;

            dataGridView_Controller1.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;//欄位標題置中//https://social.msdn.microsoft.com/Forums/zh-TW/9c555078-d4e9-44b2-a430-ffd92d237314/vb2008-datagridview?forum=232
            dataGridView_Controller1.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
            dataGridView_Controller1.RowTemplate.Height = 30;//設定高度//http://www.programmer-club.com.tw/ShowSameTitleN/csharp/9183.html
            dataGridView_Controller1.Columns[0].Width = 90;
            dataGridView_Controller1.Columns[1].Width = 90;
            dataGridView_Controller1.Columns[2].Width = 150;
            dataGridView_Controller1.Columns[3].Width = 150;
            dataGridView_Controller1.Columns[4].Width = 180;//150;
            dataGridView_Controller1.Columns[5].Width = 200;//180;
            dataGridView_Controller1.Columns[6].Width = 230;//200;
            //dataGridView_Controller1.Columns[7].Width = 230;
        }


發表迴響

你的電子郵件位址並不會被公開。 必要欄位標記為 *