Styling controls in a single table cell from the code behind - c#

I have a dynamic table where I add controls. When I open this page in Firefox the controls are unerneath each other and in Internet expl. they are horizontally aligned.
How can I set the style of this controls from the code behind?
tabCell.HorizontalAlign = HorizontalAlign.Center; // doesn't seem to work
ibtnTableOneNew.Command += eventHandelerTableOne;
ibtnTableOneNew.Attributes.Add("runat", "server");
ibtnTableOneNew.CommandArgument = i.ToString() + "|" + theRow["siteAlias"].ToString();
ibtnTableOneNew.ImageUrl = "~/img/bullet_toggle_plus.png";
tabCell.Controls.Add(ibtnTableOneNew);
tabCell.Controls.Add(cbChecked);
ibtnTableOneNewComment.Attributes.Add("runat", "server");
ibtnTableOneNewComment.ImageUrl = "~/img/Pencil.png";
tabCell.Controls.Add(ibtnTableOneNewComment);
tabRow.Cells.Add(tabCell);

Try setting tabCell.Wrap = false. That should do what you need.

Related

row0 of tableLayoutPanel keeps getting large

Good day!
We have a tableLayoutPanel, that is being use to add combo boxes and labels in runtime.
When the user clicks the button, what our code does is that, it creates the controls in runtime, and then it adds it to tableLayoutPanel's container.. When we click the 'Add' button once, we should see one cell created just like below
Now, when we add multiple controls, we notice that row 0 accumulates a large space. How do we remove that?
notice that program1 has large space, but program 2,3,4 have evenly space.. Why is that so? Thanks
Here is our code when the user clicks the 'Add' button
int cLeft = 1;
public System.Windows.Forms.ComboBox AddNewComboBox()
{
System.Windows.Forms.Label lab = new System.Windows.Forms.Label();
System.Windows.Forms.ComboBox com = new System.Windows.Forms.ComboBox();
tableLayoutPanel1.Controls.Add(lab,0,cLeft-1);
lab.Text = "Program " + cLeft.ToString() + ":";
lab.Name = "label" + cLeft.ToString();
tableLayoutPanel1.Controls.Add(com,1,cLeft-1);
com.Width = 220;
com.Name = "comboBox " + cLeft.ToString();
cLeft = cLeft + 1;
return com;
}
I encountered a similar problem once.
I think the problem is that the first row you insert is auto sized. If you add a blank row at the beginning that is auto sized and all the controls afterwards with a fixed size it should work.
Alternatively you could create an own UserControl wherein you place your label and combobox and add this with a maxheight to your tablelayout panel.

How to append a link label to an existing label?

I have a label inside a panel to display simple text. Now I have a link label that is added dynamically that displays some more information. How can I show this link label right next to the label text at run time? For example, the lable displays
A record is added.
I need to show with a link label "View Additional Details" next to the label text.
A record is added. View Additional Details
I have the code as below but it overlaps the existing label text. Thanks for any help!
LinkLabel details = new LinkLabel();
details.Text = "View Additional Details";
LinkLabel.Link link = new LinkLabel.Link();
link.LinkData = infoDetails;
details.Links.Add(link);
details.LinkClicked += new LinkLabelLinkClickedEventHandler(details_LinkClicked);
//Adding the link label control to the existing label control
lblInfo.Visible = true;
lblInfo.AutoSize = true;
lblInfo.Controls.Add(details);
Why are you trying to add a LinkLabel to a label? Add the LinkLabel to the same form as the label, and set the location of the LinkLabel appropriately.
In the example below, I'm assuming the code is being called from the form's class (or to a panel if you are using one). If not, replace this with your form instance. I'm setting the Y location as the same as lblInfo so the LinkLabel appears next to it. Adjust lblInfo.Margin.Right and details.Margin.Left as desired.
details.Margin.Left = 5;
details.Location = new Point(
lblInfo.Location.X + lblInfo.Width + lblInfo.Margin.Right + details.Margin.Left,
lblInfo.Location.Y
);
this.Controls.Add(details);
Update: changed padding to use Margin (thanks Anthony).

Dynamically Create Checkbox With Scrolling

I'm trying to build a form application in Visual Studio 2010 using C#.
The program will be reading a excel file that contains a list of filenames, and will dynamically generate textbox for each filename.
Below is my code, just for clarification. I wanted to make the label a link to the file, that's why I didn't use checkboxes[i].Text = filename
CheckBox[] checkboxes = new CheckBox[fileCount];
Label[] labels = new Label[fileCount];
for (int i = 0; i < fileCount; i++ )
{
//creating a checkbox
checkboxes[i] = new CheckBox();
checkboxes[i].Location = new Point(360, (145 + i * 30));
checkboxes[i].Name = String.Format("checkbox{0}", i.ToString());
this.Controls.Add(checkboxes[i]);
//creating filename label
labels[i] = new Label();
labels[i].Location = new Point(20, (150 + i * 30));
labels[i].Text = existingFiles[i];
labels[i].Width = 330;
this.Controls.Add(labels[i]);
}
Say if fileCount equals to 100, it will make the form really big/long and won't be able to fit properly on most monitors.
Is there a way to make all dynamically generated checkboxes and labels all grouped in a area and just have the user be able to scroll? Something like a panel with scrolling? I don't know if there's anything like that.
I thought about using CheckedListBox, but doing that way I won't be able to make the filename a link. I want the user be able to click on the label and the file will be opened automatically, instead of selecting it.
Any help is appreciated!
Most controls have the AutoScroll property. Set this to true, and the control will automatically add a scrollbar when necessary. You can use the Panel control and add all of your links/checkboxes to that (if you don't want your whole form to scroll).

CollapsiblePanelExtender should not collapse on AutoPostBack

I've got an asp.net page with some CollapsiblePanelExtender which is collapsed by default and contains CheckBoxes.
My problem is that when I expand one and check a CheckBox an AutoPostBack event is firing and my CollapsiblePanelExtender is collapsed again.
Is there a way to let the CollapsiblePanelExtender expand when I click a CheckBox with just C# and asp.net? I don't want to use JavaScript here.
Here is the configuration of my control:
CollapsiblePanelExtender cpe = new CollapsiblePanelExtender();
cpe.ID = "cpe" + headerName;
cpe.TargetControlID = headerName + "Body";
cpe.CollapsedSize = 0;
cpe.Collapsed = true;
cpe.ExpandControlID = headerName + "Header";
cpe.CollapseControlID = headerName + "Header";
cpe.AutoCollapse = false;
cpe.AutoExpand = false;
cpe.ScrollContents = false;
cpe.ExpandDirection = CollapsiblePanelExpandDirection.Vertical;
cpe.SuppressPostBack = false;
It collapses because the html is replaced with what comes from the server after the postback, therefore, the CollapsiblePanelExtender returns to the default state.
If you can use UpdatePanels, consider the following:
Put the CollapsiblePanelExtender inside an UpdatePanel. Set the UpdatePanel UpdateMode="Conditional" and ChildrenAsTriggers="false".
The client state of the html inside that updatepanel will be maintained after the Postback because the panel will not update.
If you ever need it to update, you could update it manually by calling updatePanel.Update().

creating RadEditor dynamically asp.net

I want to add RadEditor dynamically. It is getting added to the page but as soon as postback occurs i get Multiple controls with the same ID 'EditorRibbonBarResourcesHolder' were found. Below is the code that i am using to add control dynamically.
RadEditor editor = new RadEditor();
editor.ID = "editor_" + itemTypeattribute.ItemAttributeID + rand.Next();
cellAttributeValue.Controls.Add(editor);
editor.DialogOpener.ID = "editor_dialopOpener_" + itemTypeattribute.ItemAttributeID;
editor.DialogOpener.Window.ID = "editor_dialopOpener_window_"+ ItemTypeattribute.ItemAttributeID;
editor.ClientIDMode = ClientIDMode.AutoID;
editor.EnableEmbeddedScripts = true;
editor.Height = 200;
Any help is appreciated. Thanks
Whenever I need to use a radeditor "dynamically" I have it on the page from the start with visible=false and then show it when I need it.

Categories

Resources