Hi all,


I now have a very serious problem. I have a table that have to show in different datagridviews which are generated dynamically.

The table looks like this


C_id formula systemid mass user time
1 c6h6 1 23 s 00:99
2 c3h4 2 22 g 09:08
3 c7h8 1 11 f 00:88
4 c1h1 3 33 f 11:00

Now I have to show datagridviews according to "systemid", I mean there must be three datagridviews each showing one systemid which must look as

datagrid1

C_id formula systemid mass user time
1 c6h6 1 23 s 00:99
3 c7h8 1 11 f 00:88

datagrid2
2 c3h4 2 22 g 09:08

datagrid3
4 c1h1 3 33 f 11:00

now this datagridviews must not be static because there may be some more systemid later upto 6 or so. So, I must generate datagridview dynamically as many as systemid's and much more worst for me is I must be able to edit the content, add new content and delete it.

Please help me coding this part of it as it is my important part of my project before joining into a company.

I'm now doing my project in Csharp windowform.

Sorry and please feel free to post, if my explination is not clear.

>Please help me coding this part of it as it is my important part of my project before joining into a company.


Yes. I like homework but put here your code work please.

HI

I would like to, but still I'm clueless where to start with as I'm new to this C.net windows form and I think this is something advanced.

Sorry for not providing any code..

Have a look at this code-snippet.

DataGridView gv1 = new DataGridView();
            gv1.AutoGenerateColumns = false;

            DataGridViewTextBoxColumn tx1 = new DataGridViewTextBoxColumn();
            tx1.HeaderText = "Name";
            DataGridViewTextBoxColumn tx2 = new DataGridViewTextBoxColumn();
            tx2.HeaderText = "Age";

            gv1.Columns.Add(tx1);
            gv1.Columns.Add(tx2);

            gv1.Rows.Add("Mr.A", 20);
            gv1.Rows.Add("Mr.B", 40);

            gv1.Location = new Point(20, 20);

            this.Controls.Add(gv1);

Hi,

Thanks very much with the code. But as I mentioned earlier I need results in different datagridviews which are generated automatically or dynamically. I have already tried this code but was able to get only one datagrid view and don't how to get more than one dynamically and seperate the contents in the table to that paticular datagridview.

>But as I mentioned earlier I need results in different datagridviews which are generated automatically or dynamically.

Can you explain me what "automatically or dynamically" does?

Code in above post creates datagrid dynamically (programmatically).

Actually yes that the code for dynamic datagrid view but what I need is I have a table like this

C_id formula systemid mass user time
1 c6h6 1 23 s 00:99
2 c3h4 2 22 g 09:08
3 c7h8 1 11 f 00:88
4 c1h1 3 33 f 11:00

Now I have to show datagridviews according to "systemid", I mean there must be three datagridviews each showing one "systemid" which must look as

datagrid1
C_id formula systemid mass user time
1 c6h6 1 23 s 00:99
3 c7h8 1 11 f 00:88

datagrid2
2 c3h4 2 22 g 09:08

datagrid3
4 c1h1 3 33 f 11:00

If there is no systemid =2 then there must not be any grid (as in this example there must not be datagridview 2).


The only thing is my code must be flexible as the table is my sal changes such as if they add a new "Systemid of 4" then it must be able to create a new datagridview in additional to the rest.


Hope I'm clear please tell me if I'm not clear at any poisition.


Thanks a lot,
Srikanth

commented: You never try to understand. -2
if(systemid==1)
 {
            DataGridView gv1 = new DataGridView();
            gv1.AutoGenerateColumns = false;

            DataGridViewTextBoxColumn tx1 = new DataGridViewTextBoxColumn();
            tx1.HeaderText = "Name";
            DataGridViewTextBoxColumn tx2 = new DataGridViewTextBoxColumn();
            tx2.HeaderText = "Age";

            gv1.Columns.Add(tx1);
            gv1.Columns.Add(tx2);

            gv1.Rows.Add("Mr.A", 20);
            gv1.Rows.Add("Mr.B", 40);

            gv1.Location = new Point(20, 20);

            this.Controls.Add(gv1);
  }
 
if(systemid==2)
 {
            DataGridView gv1 = new DataGridView();
            gv1.AutoGenerateColumns = false;

            DataGridViewTextBoxColumn tx1 = new DataGridViewTextBoxColumn();
            tx1.HeaderText = "Name";
            DataGridViewTextBoxColumn tx2 = new DataGridViewTextBoxColumn();
            tx2.HeaderText = "Age";

            gv1.Columns.Add(tx1);
            gv1.Columns.Add(tx2);

            gv1.Rows.Add("AA", 30);
            gv1.Rows.Add("BB", 40);

            gv1.Location = new Point(110, 110);

            this.Controls.Add(gv1);
 }
......

Yes, thats cool. But what if in the later stage after I submit the project and they want to introduce a new systemid in additional to the exsisting one.
How will this code generate the datagridview for the new sytemid which is entered in the backend table?

Suppose the systemid are coming from database then,

int left=20,top=20;
foreach(DataRow r in dataTableObject.Rows)
{
   string systemid=r["systemid"].ToString();
   .....
    DataGridView gv1 = new DataGridView();
            gv1.AutoGenerateColumns = false;

            DataGridViewTextBoxColumn tx1 = new DataGridViewTextBoxColumn();
            tx1.HeaderText = "Name";
            DataGridViewTextBoxColumn tx2 = new DataGridViewTextBoxColumn();
            tx2.HeaderText = "Age";

            gv1.Columns.Add(tx1);
            gv1.Columns.Add(tx2);

            .....
            .....
            gv1.Location = new Point(left, top);
            top=top+100; 
            this.Controls.Add(gv1);
}

HI,

Yes systemId comes for the back end Sql table. This looks cool.

I will try it and let you know if I stuck some where.

Thanks a lot my friend. This mean to me a lot.

Would you mind if I ask you to post the full version of the code.

HI,

Yes systemId comes for the back end Sql table. This looks cool.

I will try it and let you know if I stuck some where.

Thanks a lot my friend. This mean to me a lot.

Would you mind if I ask you to post the full version of the code.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.