dataGridView 数据绑定

   #region  在datagridview中显示dt
       
private   void  display(DataGridView dgv,DataTable dt)
       {
           dgv.Rows.Clear();
           
if  (dt  !=   null )
           {
               
object [] item  =   new   object [dt.Columns.Count];
               
for  ( int  i  =   0 ; i  <  dt.Rows.Count; i ++ )
               {
                   
for  ( int  j  =   0 ; j  <  dt.Columns.Count; j ++ )
                   {
                       item[j] 
=  dt.Rows[i][j];
                   }
                   dgv.Rows.Add(item);
               }
           }
           dgv.Update();

       }
       
#endregion

你可能感兴趣的:(datagridview)