티스토리 툴바

달력

052012  이전 다음

  •  
  •  
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  •  
  •  
프로젝트 NO : 2011003

[ Form1] : 부모폼  , DataGridView name : datagridview1
[ Form2] : 자식폼

[Form1] 소스

private void btnAdd_Click(object sender, EventArgs e)
{
Form2 frm = new Form2();

frm.FormClosed += new FormClosedEventHandler(frm_FormClosed);
frm.ShowDialog();
}

public void frm_FormClosed(object sender, FormClosedEventArgs e)
{
dataGridView1.Update();
ListView("all");
}

public void ListView(string str)
        {
            string query = null;
            dataGridView1.Rows.Clear();
            dataGridView1.Columns.Clear();
            if(str == "all")
            {
                query = "select * from reader_info order by contents_id asc";
            }
            try {
                conn.Open();
                //MySqlDataAdapter adt = new MySqlDataAdapter(query, conn);
                adt = new MySqlDataAdapter(query, conn);
  
                //DataSet ds = new DataSet();
                ds = new DataSet();
                adt.Fill(ds,"xorbis");
                //
                dataGridView1.Columns.Add("seqid", "일련번호");
                dataGridView1.Columns.Add("contents_id", "컨텐츠정보");
                dataGridView1.Columns.Add("pc_ip", "컨텐츠아이피");
                dataGridView1.Columns.Add("reader_ip", "리더기아이피");
                //
                int row = ds.Tables["tbl"].Rows.Count - 1;
                for (int r = 0; r <= row; r++)
                {
                    dataGridView1.Rows.Add();
                    dataGridView1.Rows[r].Cells[0].Value = ds.Tables["tbl"].Rows[r].ItemArray[0];
                    dataGridView1.Rows[r].Cells[1].Value = ds.Tables["tbl"].Rows[r].ItemArray[1];
                    dataGridView1.Rows[r].Cells[2].Value = ds.Tables["tbl"].Rows[r].ItemArray[2];
                    dataGridView1.Rows[r].Cells[3].Value = ds.Tables["tbl"].Rows[r].ItemArray[3];
                }
               
            }
            catch (Exception es) {
                MessageBox.Show("ERROR" + es.ToString());
            }
            finally {
                conn.Close();
            }
        }
Posted by 불펭