| | | Dynamic Tabcontrol from database | |
I am trying to generate a form that has Tabcontrol (collection of Tabpages) & further toolstripbuttons for each of these tabpages.
I face a problem with the data from the database - for example-
Taborder Tabname Toolstripbutton
1 Tab1 TS1
1 Tab1 TS2
2 Tab2 TS1
2 Tab2 TS2
I use a dataview based on the taborder field and with a while statement will move to the next the record.
The problem is that the next value is also 1, therefore only Tab1 is created in my form, but not Tab2. How can I solve this? | | Scorgi Sunday, August 23, 2009 1:43 PM | Hi, i tried out this one its working fine for me.here my code i hope it will help you.
private void frmDynamicToolbar_Load(object sender, EventArgs e)
{
AddTab();
}
private DataSet CreateDataTable()
{
DataTable table = new DataTable("childTable");
DataColumn column;
DataRow row;
DataSet dataset=new DataSet();
// Create first column and add to the DataTable.
column = new DataColumn();
column.DataType = System.Type.GetType("System.Int32");
column.ColumnName = "ChildID";
column.AutoIncrement = true;
column.Caption = "ID";
column.ReadOnly = true;
column.Unique = true;
// Add the column to the DataColumnCollection.
table.Columns.Add(column);
// Create second column.
column = new DataColumn();
column.DataType = System.Type.GetType("System.String");
column.ColumnName = "ChildItem";
column.AutoIncrement = false;
column.Caption = "ChildItem";
column.ReadOnly = false;
column.Unique = false;
table.Columns.Add(column);
// Create third column.
column = new DataColumn();
column.DataType = System.Type.GetType("System.Int32");
column.ColumnName = "ParentID";
column.AutoIncrement = false;
column.Caption = "ParentID";
column.ReadOnly = false;
column.Unique = false;
table.Columns.Add(column);
dataset.Tables.Add(table);
// Create three sets of DataRow objects,
// five rows each, and add to DataTable.
for (int i = 0; i <= 4; i++)
{
row = table.NewRow();
row["childID"] = i;
row["ChildItem"] = "Item " + i;
row["ParentID"] = 0;
table.Rows.Add(row);
}
for (int i = 0; i <= 4; i++)
{
row = table.NewRow();
row["childID"] = i + 5;
row["ChildItem"] = "Item " + i;
row["ParentID"] = 1;
table.Rows.Add(row);
}
for (int i = 0; i <= 4; i++)
{
row = table.NewRow();
row["childID"] = i + 10;
row["ChildItem"] = "Item " + i;
row["ParentID"] = 2;
table.Rows.Add(row);
}
return dataset;
}
int count = 0;
private void AddTab()
{
DataSet ds=CreateDataTable();
DataTable tdt = ds.Tables[0];
DataView tdv = new DataView(tdt);
tdv.Sort = string.Format("{0}", tdt.Columns["ChildItem"]);
System.Collections.IEnumerator tabLayout = tdv.GetEnumerator();
Point p = new Point(50, 100);
TabControl tctoolbar = new TabControl();
while (tabLayout.MoveNext())
{
tctoolbar.Location = p;
new Point(50, 100);
tctoolbar.Size = new Size(360, 170);
tctoolbar.TabPages.Add("TAB"+count,"Key"+count,count);
tctoolbar.SelectedIndex = 1;
this.Controls.Add(tctoolbar);
Controls.Add(tctoolbar);
count = count + 1;
}
}
Best Regards, C.Gnanadurai ----------------------- Please mark the post as answer if it is helpfull to you - Proposed As Answer byGnanadurai Tuesday, August 25, 2009 9:52 AM
- Marked As Answer byScorgi Wednesday, August 26, 2009 10:41 AM
-
| | Gnanadurai Monday, August 24, 2009 1:18 PM | Hi, I hope it will help you
private void CreateTab(int tabCount)
{
TabControl tabCtrl = new TabControl();
TabPage page = new TabPage();
for (int count = 0; count < tabCount; count++)
{
page.Name = "Tab" + count;
page.TabIndex = count;
page.Text = "A" + count;
tabCtrl.TabPages.Add(page);
this.Controls.Add(tabCtrl);
}
}
Best Regards,
C.Gnanadurai
-----------------------
Please mark the post as answer if it is helpfull to you | | Gnanadurai Monday, August 24, 2009 6:26 AM | Hi, I have tried to use your code, but it does not work. Here is my code. Maybe you can find my error.
private void frmDynamicToolbar_Load(object sender, EventArgs e)
{
DB.
DataSetTab.TabLayoutSelectDataTable tdt = Tools.PcConfig.DatasetTab.TabLayoutSelect;
DataView tdv = new DataView(tdt);
tdv.Sort =
string.Format("{0}", tdt.TabOrderLeftColumn.ColumnName);
System.Collections.
IEnumerator tabLayout = tdv.GetEnumerator();
Point p = new Point(50, 100);
while (tabLayout.MoveNext())
{
DB.
DataSetTab.TabLayoutSelectRow tdrTabLayout = (DB.DataSetTab.TabLayoutSelectRow)((DataRowView)tabLayout.Current).Row;
{
tctoolbar =
new TabControl();
TabPage tp = new TabPage();
tctoolbar.Location = p;
//new Point(50, 100);
tctoolbar.Size =
new Size(360, 170);
{
for (int i = 0; i < tdrTabLayout.TabOrderLeft; i++)
{
tp.Name =
"Tab" + i;
tp.TabIndex = i;
tp.Text = tdrTabLayout.TabDescription;
tctoolbar.TabPages.Add(tp);
this.Controls.Add(tctoolbar);
}
}
//Controls.Add(tctoolbar);
}
}
}
| | Scorgi Monday, August 24, 2009 8:11 AM | Hi, Here i modified the code check and let me know
DB.DataSetTab.TabLayoutSelectDataTable tdt = Tools.PcConfig.DatasetTab.TabLayoutSelect;
DataView tdv = new DataView(tdt);
tdv.Sort = string.Format("{0}", tdt.TabOrderLeftColumn.ColumnName);
System.Collections.IEnumerator tabLayout = tdv.GetEnumerator();
Point p = new Point(50, 100);
//Here you need to create object
TabControl tctoolbar = new TabControl();
TabPage tp = new TabPage();
while (tabLayout.MoveNext())
{
DB.DataSetTab.TabLayoutSelectRow tdrTabLayout = (DB.DataSetTab.TabLayoutSelectRow)((DataRowView)tabLayout.Current).Row;
{
tctoolbar.Location = p;
//new Point(50, 100);
tctoolbar.Size = new Size(360, 170);
{
for (int i = 0; i < tdrTabLayout.TabOrderLeft; i++)
{
tp.Name = "Tab" + i;
tp.TabIndex = i;
tp.Text = tdrTabLayout.TabDescription;
tctoolbar.TabPages.Add(tp);
this.Controls.Add(tctoolbar);
}
}
//Controls.Add(tctoolbar);
}
}
Best Regards,
C.Gnanadurai
-----------------------
Please mark the post as answer if it is helpfull to you | | Gnanadurai Monday, August 24, 2009 8:57 AM | Thanks for your reply.
Almost perfect now, but it creates a tabpage everytime
Taborder Tabname Toolstripbutton
1 Tab1 TS1
1 Tab1 TS2
2 Tab2 TS1
2 Tab2 TS2
Tab1 & Tab2 should only be created once each.
Right now four tabpages are created
tab1 - tab1 - tab2 - tab2
Hope you understand. | | Scorgi Monday, August 24, 2009 9:11 AM | Hi, check out this one..
int count = 0;
private void AddTab()
{
DB.DataSetTab.TabLayoutSelectDataTable tdt = Tools.PcConfig.DatasetTab.TabLayoutSelect;
DataView tdv = new DataView(tdt);
tdv.Sort = string.Format("{0}", tdt.TabOrderLeftColumn.ColumnName);
System.Collections.IEnumerator tabLayout = tdv.GetEnumerator();
Point p = new Point(50, 100);
//Here you need to create object
TabControl tctoolbar = new TabControl();
TabPage tp = new TabPage();
while (tabLayout.MoveNext())
{
DB.DataSetTab.TabLayoutSelectRow tdrTabLayout = (DB.DataSetTab.TabLayoutSelectRow)
((DataRowView)tabLayout.Current).Row;
tctoolbar.Location = p;
//new Point(50, 100);
tctoolbar.Size = new Size(360, 170);
tp.Name = "Tab" + count;
tp.TabIndex = count;
tp.Text = tdrTabLayout.TabDescription;
tctoolbar.TabPages.Add(tp);
this.Controls.Add(tctoolbar);
count = count + 1;
//Controls.Add(tctoolbar);
}
}
Best Regards,
C.Gnanadurai
-----------------------
Please mark the post as answer if it is helpfull to you | | Gnanadurai Monday, August 24, 2009 9:34 AM | Sorry forgot to mention that before the first line ... { DB.DataSetTab.TabLayoutSelectDataTable tdt = Tools.PcConfig.DatasetTab.TabLayoutSelect; is this
private void frmDynamicToolbar_Load(object sender, EventArgs e)
{
| | Scorgi Monday, August 24, 2009 9:43 AM | Hi, i created like a method call that method in the frmDynamicToolbar_Load event.
Best Regards,
C.Gnanadurai
-----------------------
Please mark the post as answer if it is helpfull to you | | Gnanadurai Monday, August 24, 2009 9:58 AM | Sorry that I just can't figure this out, but I am unable to call the Method you want me to call.
private void frmDynamicToolbar_Load(object sender, EventArgs e)
{
int count = 0;
private void AddTab()
{
I have problems with { and have tried to set }, but it does not help.
| | Scorgi Monday, August 24, 2009 11:03 AM |
int count=0;
private void frmDynamicToolbar_Load(object sender, EventArgs e)
{
AddTab();
}
private void AddTab()
{
DB.DataSetTab.TabLayoutSelectDataTable tdt = Tools.PcConfig.DatasetTab.TabLayoutSelect;
DataView tdv = new DataView(tdt);
tdv.Sort = string.Format("{0}", tdt.TabOrderLeftColumn.ColumnName);
System.Collections.IEnumerator tabLayout = tdv.GetEnumerator();
Point p = new Point(50, 100);
//Here you need to create object
TabControl tctoolbar = new TabControl();
TabPage tp = new TabPage();
while (tabLayout.MoveNext())
{
DB.DataSetTab.TabLayoutSelectRow tdrTabLayout = (DB.DataSetTab.TabLayoutSelectRow)
((DataRowView)tabLayout.Current).Row;
tctoolbar.Location = p;
//new Point(50, 100);
tctoolbar.Size = new Size(360, 170);
tp.Name = "Tab" + count;
tp.TabIndex = count;
tp.Text = tdrTabLayout.TabDescription;
tctoolbar.TabPages.Add(tp);
this.Controls.Add(tctoolbar);
count = count + 1;
//Controls.Add(tctoolbar);
}
}
Best Regards,
C.Gnanadurai
-----------------------
Please mark the post as answer if it is helpfull to you | | Gnanadurai Monday, August 24, 2009 11:18 AM | First of all thanks for all your help I appreciate it very much.
Unfortunately the result is the same.
A lot of the same tabpages appear.
| | Scorgi Monday, August 24, 2009 12:16 PM | Hi, i tried out this one its working fine for me.here my code i hope it will help you.
private void frmDynamicToolbar_Load(object sender, EventArgs e)
{
AddTab();
}
private DataSet CreateDataTable()
{
DataTable table = new DataTable("childTable");
DataColumn column;
DataRow row;
DataSet dataset=new DataSet();
// Create first column and add to the DataTable.
column = new DataColumn();
column.DataType = System.Type.GetType("System.Int32");
column.ColumnName = "ChildID";
column.AutoIncrement = true;
column.Caption = "ID";
column.ReadOnly = true;
column.Unique = true;
// Add the column to the DataColumnCollection.
table.Columns.Add(column);
// Create second column.
column = new DataColumn();
column.DataType = System.Type.GetType("System.String");
column.ColumnName = "ChildItem";
column.AutoIncrement = false;
column.Caption = "ChildItem";
column.ReadOnly = false;
column.Unique = false;
table.Columns.Add(column);
// Create third column.
column = new DataColumn();
column.DataType = System.Type.GetType("System.Int32");
column.ColumnName = "ParentID";
column.AutoIncrement = false;
column.Caption = "ParentID";
column.ReadOnly = false;
column.Unique = false;
table.Columns.Add(column);
dataset.Tables.Add(table);
// Create three sets of DataRow objects,
// five rows each, and add to DataTable.
for (int i = 0; i <= 4; i++)
{
row = table.NewRow();
row["childID"] = i;
row["ChildItem"] = "Item " + i;
row["ParentID"] = 0;
table.Rows.Add(row);
}
for (int i = 0; i <= 4; i++)
{
row = table.NewRow();
row["childID"] = i + 5;
row["ChildItem"] = "Item " + i;
row["ParentID"] = 1;
table.Rows.Add(row);
}
for (int i = 0; i <= 4; i++)
{
row = table.NewRow();
row["childID"] = i + 10;
row["ChildItem"] = "Item " + i;
row["ParentID"] = 2;
table.Rows.Add(row);
}
return dataset;
}
int count = 0;
private void AddTab()
{
DataSet ds=CreateDataTable();
DataTable tdt = ds.Tables[0];
DataView tdv = new DataView(tdt);
tdv.Sort = string.Format("{0}", tdt.Columns["ChildItem"]);
System.Collections.IEnumerator tabLayout = tdv.GetEnumerator();
Point p = new Point(50, 100);
TabControl tctoolbar = new TabControl();
while (tabLayout.MoveNext())
{
tctoolbar.Location = p;
new Point(50, 100);
tctoolbar.Size = new Size(360, 170);
tctoolbar.TabPages.Add("TAB"+count,"Key"+count,count);
tctoolbar.SelectedIndex = 1;
this.Controls.Add(tctoolbar);
Controls.Add(tctoolbar);
count = count + 1;
}
}
Best Regards, C.Gnanadurai ----------------------- Please mark the post as answer if it is helpfull to you - Proposed As Answer byGnanadurai Tuesday, August 25, 2009 9:52 AM
- Marked As Answer byScorgi Wednesday, August 26, 2009 10:41 AM
-
| | Gnanadurai Monday, August 24, 2009 1:18 PM | Thank you so much for your help.
| | Scorgi Wednesday, August 26, 2009 10:41 AM |
| |
You can use google to search for other answers |
|
|
|
| | More Threads | | | How to make combobox can insert other data that not exist in items list? | | Step by step instruction. Open Form2 from Button on form1 C# | | missing taskbar button | | Keeping info on a page | | Dropdown menu without custom typing ablity | | How to open the txt file by using none-default editor, e.g. "WinEdit.exe"? | | list box Items | | Forms -> Html, CSS, others? | | Customizing treeview | | Assemby | |
|