Hello:
I need to create/define a temp/work DataGridView in a Class so I can do some pre-work. I tried the following line, but it seems to not work. Can someone tell me if its right or what I am missing?
DataGridView dataGridViewTemp = new DataGridView();
Loading

Marimuthu ArigovindasamyRank #5,893 · 283 reputationPosted Jun 7, 2010, 5:13 PM EDT
DataTable dt = new DataTable();
dt.Columns.Add("Name");
DataRow dr = dt.NewRow();
dr["Name"] = "Muthu";
dt.Rows.Add(dr);
GridView grd = new GridView();
grd.ID = "grdView1";
grd.EmptyDataText = "The data is empty.";
form1.Controls.Add(grd);
grd.DataSource = dt;
grd.DataBind();
GustavoRank #1,990 · 732 reputationPosted Jun 7, 2010, 7:46 PM EDT
I needed to do it for a DataGridView instead if a DataGrid. I am new, but I think that they act really different.
Also, the grd.ID comes up as an error. Probably because I dont have the 'using' for it.
Marimuthu ArigovindasamyRank #5,893 · 283 reputationPosted Jun 7, 2010, 9:38 PM EDT
Sorry, I thought that, U r working in Web appl. Try the below code.
DataTable dt = new DataTable();
dt.Columns.Add("Name");
DataRow dr = dt.NewRow();
dr["Name"] = "Muthu";
dt.Rows.Add(dr);
DataGridView dgv = new DataGridView();
dgv.Name = "dgv1";
this.Controls.Add(dgv);
dgv.DataSource = dt;
GustavoRank #1,990 · 732 reputationPosted Jun 7, 2010, 9:42 PM EDT
I am using VS 2008 & 2010. BTW: I am using C# Forms not Web stuff.
In C# Windows Form its dataGridView
Marimuthu ArigovindasamyRank #5,893 · 283 reputationPosted Jun 7, 2010, 9:55 PM EDT
Marimuthu ArigovindasamyRank #5,893 · 283 reputationPosted Jun 7, 2010, 9:59 PM EDT
dgv.Name = "dgv1";
dgv.Location = new Point(27, 180);
dgv.Size = new Size(240, 150);
GustavoRank #1,990 · 732 reputationPosted Jun 7, 2010, 10:00 PM EDT
GustavoRank #1,990 · 732 reputationPosted Jun 7, 2010, 10:15 PM EDT
What I am really trying to do is take some code from my MDIChild Form and put it in my Class ClassControl.
In my MDIChild Form I have the following code in the Form_Load:
ClassDB.LoadDataTableRecord(RunAs, dataGridViewTemp);
I am trying to put it in my Class ClassControl like the following, but it give me an error at run time.
ClassDB.LoadDataTableRecord(RunAs, ((Form)sender).GetType().GetField("dataGridViewTemp").GetValue(((Form)sender));
Maybe I some syntax wrong?