The problem is as:
I have horizontal asp:RadioButtonList, with 3 buttons witch i add programaticly C# code
The thing is that the third button must be on second line. How can i do it besides creating a new asp:RadioButtonList?
I have tried adding br and \r\n to caption but that dose not help me.
ListItem _item1 = new ListItem("1", "1");
ListItem _item2 = new ListItem("2", "2");
ListItem _item3 = new ListItem("3", "3");
rbl.Items.Add(_item1);
rbl.Items.Add(_item2);
rbl.Items.Add(_item3);
Use the RepeatColumns property ? Set it to 2 and the third one should bump down a line. This creates a column approach. Only downside to it if the labels are long it might not look right.
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.radiobuttonlist.repeatcolumns.aspx
If the labels are really long, then I would suggest moving to a repeater or listview and roll your own. You could use a placeholder control in the item template and in the itemdatabound event add the radio buttons based the count or index and use a mod to decide when to place a break element. Definitely a hack though.
You could look into using CssAdapters they offer a lot of flexibility for tweaking control layouts.
Related
Every time this Dropdown is showing first Item Blank
ComboBox cb;
List<string> namesCollection=new List<string>();
namesCollection.Add("---- Select ----");
namesCollection.Add("ABC1");
namesCollection.Add("ABC2");
namesCollection.Add("ABC3");
namesCollection.Add("ABC4");
foreach(string pname in namesCollection)
cb.Items.Add(pname);
Does anyone have solution for this ?
You appear to be defining the ComboBox right there in your code, so I'll assume it's actually displayed somewhere in your form / window.
It's normal for the ComboBox to display a blank line initially.
Specify the item you want to display, immediately after populating the ComboBox with data:
cb.SelectedIndex = 0;
You probably have a line feed in your items collection. Hard to see. Adding a cb.Items.Clear() before populating is probably a good idea anyway and will get rid of the problem, if you can't locate it.
Hi Sorry if the answer has been given already, but I have searched high and low for this and have drawn a blank.
I have a grid of buttons that disappear when clicked. This is good. The buttons are named tile1, tile2, tile3 etc... their numbers are contiguous.
Their click_handlers currently each manually 'disappear' the sending buttons like this...:
tile1.visible = false
I am looking for a simple way to reference the tile names and numbers so I can
disappear the buttons in groups by referencing their names and numbers (ie disappear the 1st 3 in one command (or loop) followed by the next 2 together followed by the next 6 together... you get the picture).
Create a reset loop that resets the buttons' visibility property from within the code without having to manually type every button name.
So in an ideal world it might look something like...:
for (i=1; i<=MAX_TILE_NUMBER; ++i)
{
string currentTile = "tile" + i
currentTile.visible = false
}
I can feel it in my bones that there is an easy way to concatenate the string portion of the button name with the index "i" in my for loop and use this to reference the button controls one by one or in groups but I have not yet found it. please save me from imminent hair-rending insanity.
Many thanks.
Thanks
JB
Just put your buttons to a collection, a dictionary should fit best for you.
var buttons = new Dictionary<string, Button> { { "tile1", tile1 }, ... };
buttons.Add("tile2", tile2);
etc.
and then operate with this dictionary. For example, make the first three buttons invisible
var firstThree = buttons.Take(3);
foreach (var b in firstThree)
b.Value.Visible = false;
You can pick buttons however you wish by forming LINQ queries on this dictionary.
There is function to find control by name
see http://msdn.microsoft.com/en-us/library/system.windows.forms.control.controlcollection.find%28VS.80%29.aspx
Is there a way to show the subitems of an item in a listview below it? I don't want to separate the item in first column and subsequent subitems in subsequent columns, I want it all in a single column and if there were to be more items I want every item separated by a line. Something like this but in C#.
Maybe if it is not possible could it be to make every item like an expandable list?
My code for now is:
lstEvents.View = View.Details;
lstEvents.ForeColor = Color.Black;
lstEvents.Columns.Add("Events");
ListViewItem item = new ListViewItem("Event name");
item.SubItems.Add("23/04/2012");
item.SubItems.Add("$20000");
item.SubItems.Add("this would be the event description");
im using windows forms
In Tile view, each "column" appears as a "row" under the primary column. This will give you what you asked for, but probably not what you want.
You can owner draw the Tile view to produce something like this
(source: sourceforge.net)
You can do this all yourself using just a plain ListView, but the ObjectListView project makes this much easier.
You could subclass the listview and do it yourself.
Or, you can tag certain rows as subrows of the one above it using .Tag = IndexOfPreviousRow and track the relationships in a model. It's kinda hacky, though.
As far as doing it natively with the .NET listview, I don't believe you can.
I need to populate a list that has 3 columns.
First: Icon Image.
Second: A string.
Third: A string.
I started to wire up a DataGridView and it seem awfully large and powerful for my needs. I am not interested in displaying data in a grid similar to a spreadsheet and I do not require all the functionality that comes with this control. Is there a better alternative?
Thanks!
You could go for the ListView in View.Details view, as this is similar to the view that you see in Windows Explorer when in Details view.
Create a form and place on it an ImageList and a ListView named imageList1 and listView1 respectively. Then place the following code into the forms load method:
listView1.Columns.Add("Image");
listView1.Columns.Add("Text1");
listView1.Columns.Add("Text2");
listView1.SmallImageList = imageList1;
var icon = Icon.ExtractAssociatedIcon(#"c:\windows\explorer.exe");
imageList1.Images.Add(icon);
var item = new ListViewItem();
item.ImageIndex = 0;
var subItem1 = new ListViewItem.ListViewSubItem();
subItem1.Text = "Text 1";
var subItem2 = new ListViewItem.ListViewSubItem();
subItem2.Text = "Text 2";
item.SubItems.Add(subItem1);
item.SubItems.Add(subItem2);
listView1.Items.Add(item);
The code really couldn't hurt for some tidying up, but it calls out quite explicitly what it's doing and should hopefully make it quite clear how to use a ListView for this purpose.
You could try ListView. You'll want to use the Columns property and Details mode.
I have a drop down list box which has one of the values to be others. I want to move these value to the last. Please help me with this. The code i am using is as follows
ddlAssetsCountryOthersone.DataSource = lstIMAssetsByCountryOthers;
ddlAssetsCountryOthersone.DataTextField = "AssetDescription";
ddlAssetsCountryOthersone.DataValueField = "AssetDescription";
ddlAssetsCountryOthersone.DataBind();
ddlAssetsCountryOthersone.Items.Remove(
ddlAssetsCountryOthersone.Items.FindByValue(
Constants.PhilosophyAndEmphasis.Other.ToString()));
How can i add the others back to the drop down list in the last
try this after your databind :
ddlAssetsCountryOthersone.Items.Add(new ListItem("Others", "Others"));
By the way if you use Insert method, you can insert the item you want to the position you want. For example the code below adds the Other option to the 4th order :
ddlAssetsCountryOthersone.Items.Insert(4, new ListItem("Others", "Others"));
you can try like
ListItem li = new ListItem("text", "value");
yourDropdown.Items.Insert(yourDropdown.Items.Count, li);
If you have 5 items in dropdown, it will return 5, since the insert index start from 0
If you the dropdownlist is databound you will not be able to add items to your control after the DataBind() call, and if you add them before they will be cleared anyway whe you call DataBind().
You can use Insert or Add after the data binding takes place, and you can specify the index of the item you're inserting. Insert is used to insert at the specific location, Add will append to the bottom, as in your case:
//after databind
//example with insert - (-1 as list is zero based)
ddlMyList.Items.Insert(noOfItems-1, "Other");
OR
//add
ddlMyList.Items.Add("Other");
Or:
ListItem li = ddlAssetsCountryOthersone.FindByValue(Constants.PhilosophyAndEmphasis.Other.ToString()));
ddlAssetsCountryOthersone.Remove(li);
ddlAssetsCountryOthersone.Add(li);
That should work, please test - and replace Add with Insert as per JohnIdol's suggestion...
When databinding, it is far easier to add/remove items from the list that is being databound than it is to add/remove items after the data binding takes place.
I would create a wrapper around lstIMAssetsByCountryOthers that makes the necessary changes into a new IEnumberable and returns that new object to be databound.