|
Hi all,
Here i have strucked with one problem that is i am adding tabcontrols dynamically. Here i want the code to add grid view control to the tabcontrols which i have generated dynamically. Means if i generated the tabcontrol one then in that tabcontrol i have to generate the grid view conrol and if i generate that tabcontrol two then add gridview control 2 to that.
Please help me in this query. Its very urjent. give reply asap.
Thank you in advance.
|
| Sahasra Thursday, April 24, 2008 6:15 AM |
Hi,
Iapologize as I thought since you mentioned GridView, you are referring to asp.net. You probably mean DataGridView.
Anyways, you cannot add a control directlyto the TabControl. You have to create a TabPage in the TabControl and then add the control to it.
Something like this:
Code Snippet
TabControl tc = new TabControl();
TabPage tp = new TabPage("First");
tc.Controls.Add(tp);
DataGridView dgv = new DataGridView();
dgv.Location = new Point(20, 10);
tp.Controls.Add(dgv);
this.Controls.Add(tc);
HTH, Suprotim Agarwal |
| Suprotim Agarwal Thursday, April 24, 2008 8:41 AM |
Hi,
Where are you adding the TabControl to the controls collection of the form?
This code works at my end. You can replace i < 4 with "lbProjname.Items.Count"
Code Snippet
TabControl tc = new TabControl();
for (int i = 0; i < 4; i++)
{
TabPage tp = new TabPage("Item" + i);
DataGridView dgv = new DataGridView();
dgv.Columns.Add("ExampleID", "Example");
dgv.Columns.Add("Status", "Status");
dgv.Location = new Point(20, 10);
tp.Controls.Add(dgv);
tc.Controls.Add(tp);
}
this.Controls.Add(tc);
}
HTH, Suprotim Agarwal
|
| Suprotim Agarwal Friday, April 25, 2008 8:52 AM |
|
| Suprotim Agarwal Friday, May 09, 2008 5:04 AM |
use an array of buttons, and reder them like a tab control.
use only one grid and populate it according to the button clicked.
thanks |
| Navtej Dhillon Thursday, April 24, 2008 6:24 AM |
Hi Navtej,
Thanks for the quck response. But here i want to generate the grid view dynamically. Means at the same time tabcontrol and grid view generated. If i use buttons instead of this, there we can add grid view in button click event of button . But i want both tabcontrol/button and grid view at a time.
Thanks.
|
| Sahasra Thursday, April 24, 2008 6:33 AM |
Hi,
Correct me if I am wrong but I assume this is an asp.net question. If so,there is a forum dedicated to asp.net and related technologies where you would get better responses.
Kindly post this question in the asp.net forums at http://forums.asp.net
HTH, Suprotim Agarwal
|
| Suprotim Agarwal Thursday, April 24, 2008 6:42 AM |
HI Suprom Agarwal
It is windows application with c#.net only. Can you suggest me for this query.
Thanks,
|
| Sahasra Thursday, April 24, 2008 6:45 AM |
Hi,
Iapologize as I thought since you mentioned GridView, you are referring to asp.net. You probably mean DataGridView.
Anyways, you cannot add a control directlyto the TabControl. You have to create a TabPage in the TabControl and then add the control to it.
Something like this:
Code Snippet
TabControl tc = new TabControl();
TabPage tp = new TabPage("First");
tc.Controls.Add(tp);
DataGridView dgv = new DataGridView();
dgv.Location = new Point(20, 10);
tp.Controls.Add(dgv);
this.Controls.Add(tc);
HTH, Suprotim Agarwal |
| Suprotim Agarwal Thursday, April 24, 2008 8:41 AM |
Hi Suprotim Agarwal,
Here i have already written this code, see once. I am getting the tab controls dynamically, and grid view control also but in last tab control only i am getting tab control.
Here i have added tab controls according to the list box control items count.(If there are 4 items in list box then 4 tab controls added).
But i am getting the Grid view control in last control that is in tabcontrol4. I am unable to get in exach and every tab control. See once below code.
try
{
DataGridView dgv = new DataGridView();
//To bind list view items to Tabcontrol start
for (int i = 0; i < lbProjname.Items.Count; i++)
{
lbProjname.HorizontalScrollbar = false;
string item = lbProjname.Items .ToString();
TabPage tabPage = new TabPage(item);
tbcProgressbar.TabPages.Add(tabPage);
////Add Datagridview control to Tab control
tabPage.Controls.Add(dgvTabcontrol);
////this.Controls.Add(tabPage);
}
Thanks |
| Sahasra Thursday, April 24, 2008 9:29 AM |
Hi,
One quick observation :
Instead of
Code Snippet
////Add Datagridview control to Tab control
tabPage.Controls.Add(dgvTabcontrol);
shouldn't this be
Code Snippet
////Add Datagridview control to Tab control
tabPage.Controls.Add(dgv);
HTH, Suprotim Agarwal
|
| Suprotim Agarwal Thursday, April 24, 2008 2:38 PM |
Hi Suprotim Agarwal,
I have written thia only,
////Add Datagridview control to Tab control
tabPage.Controls.Add(dgv);
Its unfortunately typed as
tabPage.Controls.Add(dgvTabcontrol);
But no use, give any another solution to this. And i want to add columns (Example ID, Status, and one more column with Progress bar in this Data grid view control.) Please help me in this query. Its very very urgent. Give reply asap.
Thanks |
| Sahasra Friday, April 25, 2008 3:46 AM |
Hi,
Where are you adding the TabControl to the controls collection of the form?
This code works at my end. You can replace i < 4 with "lbProjname.Items.Count"
Code Snippet
TabControl tc = new TabControl();
for (int i = 0; i < 4; i++)
{
TabPage tp = new TabPage("Item" + i);
DataGridView dgv = new DataGridView();
dgv.Columns.Add("ExampleID", "Example");
dgv.Columns.Add("Status", "Status");
dgv.Location = new Point(20, 10);
tp.Controls.Add(dgv);
tc.Controls.Add(tp);
}
this.Controls.Add(tc);
}
HTH, Suprotim Agarwal
|
| Suprotim Agarwal Friday, April 25, 2008 8:52 AM |
Hi Agarwal,
Now it is working, that is generating the grid view controls to tab control. Here you mentioned that while adding grid view columns like Example Id, Status...like this i have taken one data table and binded this with data grid view control. But i want to add progress bar control in the column "Status". See below my code. Here how can i add progress bar controls dynamically. Here i am biniding the data(URLS) from one file. And here i want to generate the progressbar controls to Row of "Status" column.
Give reply as soon as possible, its very urjent.
try
{
//To bind list view items to Tabcontrol start
//TabControl tc = new TabControl();
for (int i = 0; i < lbProjname.Items.Count; i++)
{
string item = lbProjname.Items .ToString();
if (!String.IsNullOrEmpty(item))
{
TabPage tabPage = new TabPage(item);
DataGridView dgv = new DataGridView();
//dgv.Columns.Add("Status");
dgv.Size = new Size(600, 200);
tbcProgressbar.TabPages.Add(tabPage);
DataTable dt = new DataTable("tbl");
DataColumn column = new DataColumn();
DataColumn column1 = new DataColumn();
DataColumn column2 = new DataColumn();
DataColumn column3 = new DataColumn();
DataRow row, row1, row2;
// Create new DataColumn, set DataType, ColumnName
//and add to DataTable.
//column = new DataColumn();
column.DataType = System. Type.GetType("System.Int32");
column.ColumnName = "ID";
column1.DataType = System. Type.GetType("System.String");
column1.ColumnName = "URL";
column2.DataType = System. Type.GetType("System.String");
column2.ColumnName = "Status";
//Add the Column to the DataColumnCollection.
dt.Columns.Add(column);
dt.Columns.Add(column1);
dt.Columns.Add(column2);
ImageSettings objImageSettings = new ImageSettings();
objImageSettings = ImageSettings.Restore(Application.StartupPath +"\\Projects\\"+ item + ".xml");
//int k;
//string filename = "C:\\Sites.txt";
//StreamReader sr19 = new StreamReader(filename);
//string file_names19 = sr19.ReadToEnd();
//file_names19 = file_names19.Replace("\r\n", "\r");
//string[] filenames19 = file_names19.Split('\r');
ProgressBar pbr = new ProgressBar();
for (int u = 0; u < objImageSettings.Sites.Count; u++)
{
row = dt.NewRow();
row[ "ID"] = u + 1;
row[ "URL"] = Convert.ToString(objImageSettings.Sites );
row[ "Status"] = "";
//row["Status"] = dgv.Controls.Add(pbr);
dt.Rows.Add(row);
}
//To get the files from Image settings
DataSet ds = new DataSet();
ds.Tables.Add(dt);
dgv.DataSource = ds.Tables[0];
tabPage.Controls.Add(dgv);
//dgv.Controls.Add(pbr);
//dgv.Rows.Add(pbr);
//dgv.CellFormatting +=new DataGridViewCellFormattingEventHandler(dgv_CellFormatting);
}
}
}
catch (Exception exc2)
{
MessageBox.Show("Projects are not there to generate the Thumbnails");
} |
| Sahasra Tuesday, May 06, 2008 4:44 AM |
|
| Suprotim Agarwal Friday, May 09, 2008 5:04 AM |