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
GustavoPosted Jun 8, 2010, 2:15 AM
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?
GustavoPosted Jun 8, 2010, 2:00 AM
Marimuthu ArigovindasamyPosted Jun 8, 2010, 1:59 AM
dgv.Name = "dgv1";
dgv.Location = new Point(27, 180);
dgv.Size = new Size(240, 150);
Marimuthu ArigovindasamyPosted Jun 8, 2010, 1:55 AM
GustavoPosted Jun 8, 2010, 1:42 AM
I am using VS 2008 & 2010. BTW: I am using C# Forms not Web stuff.
In C# Windows Form its dataGridView
Marimuthu ArigovindasamyPosted Jun 8, 2010, 1:38 AM
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;
GustavoPosted Jun 7, 2010, 11:46 PM
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 ArigovindasamyPosted Jun 7, 2010, 9:13 PM
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();