I have a list of strings that I loop throu, and then add them in a Accordion. When I've added all of them I want the last item to expand. The code looks like this:
for (int i = 0; i < ivDialogList.Count; i++)
{
AccordionItem ai = new AccordionItem();
ai.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch;
ai.HorizontalContentAlignment = System.Windows.HorizontalAlignment.Stretch;
ai.Content = ivDialogList[i].Message;
ai.Header = ivDialogList[i].PostType + " " + ivDialogList[i].User + " " + ivDialogList[i].PostDate;
if (i == ivDialogList.Count - 1)
ai.IsSelected = true;
content.Items.Add(ai);
}
This is working fine, but as soon as I click on any of the other accordion items or close the last one, I get an out of range exception. Does any body have another way of doing this or know the reason why I get the exception and can help.
Thanks
This works fine for me using "Lore Ipsum.." text, the toolkit Accordion and a bunch of AccordionItems - the problem must be in some of your code that you are not showing here. Can you post a stacktrace and the XAML?
I managed to solve the question. I think the problem was somewhere in the loop, and probably specific for my code. What I did was that I moved the:
if (i == ivDialogList.Count - 1)
ai.IsSelected = true;
part in the loop out, so it would be set after the loop is done, like this:
((AccordionItem)content.Items[ivDialogList.Count - 1]).IsSelected = true;
And that made it work like a charm.
Related
So, I followed a couple of tutorials on TabControl with a Close Button, and I came up with a solution- however, it seems that by pressing the close button, it also closes the next tab over and sometimes the next tab after that.
Here is the MouseDown code:
var CloseImage = Properties.Resources.Close;
for (var i = 0; i < this.tabControl1.TabPages.Count; i++)
{
var tabRect = this.tabControl1.GetTabRect(i);
tabRect.Inflate(Convert.ToInt32(-3.5), -2);
var imageRect = new Rectangle(tabRect.Right - CloseImage.Width,
tabRect.Top + (tabRect.Height - CloseImage.Height) / 2,
CloseImage.Width,
CloseImage.Height);
if (imageRect.Contains(e.Location))
{
if (tabControl1.TabCount > 1)
{
this.tabControl1.TabPages.RemoveAt(i);
return;
}
}
}
The TabControl.DrawMode is OwnerDrawFixed
It draws just fine, (hence why I'm not posting the draw code.) but, there seems to be a problem with the MouseDown event that I can't seem to find myself..
Any idea why it's closing multiple tabs instead of just the one I wanted it to? Thanks :)
My guess is the tabControl.MouseDown += ...; has been assigned multiple times by mistake.
I have very strange problem in Visual Studio. I created grid on my windows form with 10 columns.
Everything works fine until I reordered the columns - all columns disappear!
I click undo, it gives back to me only 6 columns.
When I want to add 4 columns that are missing, the program throw error: This column already exist(or something like that). Then I have to get the latest version (I checked in before) to get all columns back. When I change anything in grid, same error happens every time. I tried to delete grid and make new one - same error. I even tried to delete WF and make new one - same error.
Any idea why is this happening?
Any idea how to reorder columns in code and bypass this strange error?
Best way is to control the code and not the same assistant you are doing.
To do this use the following example:
if (dataGridView1.DataSource != null)
{
dataGridView1.Columns["idColumn1"].HeaderText = "Text 1";
dataGridView1.Columns["idColumn1"].Width = 60;
dataGridView1.Columns["idColumn1"].Index = 0;
dataGridView1.Columns["idColumn2"].HeaderText = "Text 2";
dataGridView1.Columns["idColumn2"].Width = 60;
dataGridView1.Columns["idColumn2"].Index = 1;
dataGridView1.Columns["idColumn3"].HeaderText = "Text 3";
dataGridView1.Columns["idColumn3"].Width = 60;
dataGridView1.Columns["idColumn3"].Index = 2;
dataGridView1.Columns["idColumn4"].Visible= false;
dataGridView1.Columns["idColumn5"].Visible= false;
dataGridView1.Columns["idColumn6"].Visible= false;
}
I know that the main problem is not resolved, but if somebody have same error, you can reorder your columns in code like this:
private void TransakcijaZaFakturisanje_Load(object sender, EventArgs e)
{
gridTransakcijaZaFakturisanje.Columns["SifraTransakcije"].DisplayIndex = 0;
gridTransakcijaZaFakturisanje.Columns["Opis"].DisplayIndex = 1;
gridTransakcijaZaFakturisanje.Columns["SifraKomitenta"].DisplayIndex = 2;
gridTransakcijaZaFakturisanje.Columns["IdUgovor"].DisplayIndex = 3;
gridTransakcijaZaFakturisanje.Columns["IdUsluga"].DisplayIndex = 4;
gridTransakcijaZaFakturisanje.Columns["VaziOd"].DisplayIndex = 5;
gridTransakcijaZaFakturisanje.Columns["VaziDo"].DisplayIndex = 6;
//and so on...
}
I will continue to research the problem, if I find something usefull I will type it here. Thank you all for your support!
I've got a requirement where I need to be able to click dynamically generated div's
So,I've generated buttons also dynamically and want to link the ClickEvent of Button to div's Click event.
for (int i = 0; i < DtUsers.Rows.Count; i++)
{
ASPxButton btnButton = new ASPxButton();
btnButton.ID = "btnButton" + (i + 1);
btnButton.Visible = false;
btnButton.Click += new EventHandler(this.btnButton_Click);
btntButton.CommandArgument = DtOnlineUsers.Rows[i]["USER_ID"].ToString();
var divCustomItem = new HtmlGenericControl("div");
divUandMeUsers.Controls.Add(divCustomChatItem);
divCustomItem.Controls.Add(btnButton);
divCustomItem.Attributes.Add("onclick", "document.getElementById('<%= " + btnButton.ClientID + " %>').click()");
}
But,it is not working. Can you tell me where I've done wrong?
Is there something I need to do with the UpdatePanel AsyncPostBackTrigger?
When I click the div, in the developer tools, it is saying Uncaught TypeError: Cannot read property 'click' of null
Change
divCustomItem.Attributes.Add("onclick", "document.getElementById('<%= " + btnButton.ClientID + " %>').click()");
to
divCustomItem.Attributes.Add("onclick", "document.getElementById('" + btnButton.ClientID + "').click()");
You don't need the client side server includes during a server side operation.
Edit: OK so I've gone through your code with a finer toothed comb and I've found these additional problems:
The button's visibility is set to false so it won't even be rendered. If you want it to be clickable then you will need to hide it using css visibility.
What is an ASPxButton? Did you mean Button?
As there is nothing in the div its auto height and width will be set to zero.
Try sorting out those issues and post your new code if this still does not work.
I found a bug on my site and I can't seem to find a solution. I am dynamically generating controls, two of which are a RadDatePicker and a RadTimePicker. When different events occur on the page, I am changing the visibility of the controls between true and false after generating them (essentially based on whether the page is in 'edit' mode or view mode). However, after the first instance where the controls are visible, the controls lose their styles. Refer to the screenshot below:
If anyone has any suggestions, or advice, that'd be great. Thanks
Update: Here is the code as requested
This hides and shows controls(just change true/false)
for (int i = 0; i < customProperties.Rows.Count; i++)
{
customProperties.FindControl("CustomControl" + (i + 1).ToString()).Visible = false;
customProperties.FindControl("lblCustomControl" + (i + 1).ToString()).Visible = true;
Type aType = customProperties.FindControl("CustomControl" + (i + 1).ToString()).GetType();
if (aType.Name == "RadBinaryImage")
customProperties.FindControl("CustomControl" + (i + 1).ToString() + "_btn").Visible = false;
}
So basically it searches the htmltable (customProperties) for controls and changes the visibility
This is where the control is generated:
case DynamicFieldTypeEnum.Date:
RadDatePicker dp = new RadDatePicker();
dp = currentValues as RadDatePicker;
if (dp.SelectedDate == null)
customProperty.Text = "Not Specified";
else
customProperty.Text = dp.SelectedDate.Value.ToString(dp.DateInput.DateFormat);
dp.ID = "CustomControl" + (position + 1).ToString();
newControls[0] = customProperty;
newControls[1] = dp;
break;
case DynamicFieldTypeEnum.Time:
RadTimePicker tp = new RadTimePicker();
tp = currentValues as RadTimePicker;
if (tp.SelectedDate == null)
customProperty.Text = "Not Specified";
else
customProperty.Text = tp.SelectedDate.Value.ToString(tp.DateInput.DateFormat);
tp.ID = "CustomControl" + (position + 1).ToString();
newControls[0] = customProperty;
newControls[1] = tp;
break;
This is within a method that is given an object definition and then returns a control array. The first value in the control array is a label for "view" mode and the second control is a control for "edit" mode.
This array is then passed to a different method which places the controls within a table cell which is placed in a table row and then placed in the table "customProperties"
I have already experienced this kind of problem.
As a suggestion of Telerik Support, I added this code in the pages I found your problems.
<telerik:RadStyleSheetManager ID="RadCssManager" runat="server">
<StyleSheets>
<telerik:StyleSheetReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Skins.RadDatePicker.css" />
<telerik:StyleSheetReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Skins.MetroTouch.RadDatePicker.MetroTouch.css" />
</StyleSheets>
</telerik:RadStyleSheetManager>
Ps: in my case I'm using the "MetroTouch" Skin.
I'm developing a Silverlight 3 app and getting this really weird error when I try to add an object to a Canvas. My code is as follows:
for (int i = 0; i < person.Children.Count; i++)
{
//Add children in same position as parent
Person child = person.Children[i];
child.x_PositionTransform.X = person.x_PositionTransform.X;
child.x_PositionTransform.Y = person.x_PositionTransform.Y;
child.Click += new RoutedEventHandler(person_Click);
x_LayoutRoot.Children.Add(child);
}
The first time I use this, it works as expected. However, when I hit x_LayoutRoot.Children.Add(child) after clicking a Person object that was created using this code, I get an ArgumentException telling me that "Value does not fall within the expected range."
However, when I add the following code before adding child to x_LayoutRoot.Children, the problem disappears.
child.SetValue(Canvas.NameProperty, "child" + objCount++);
Why is this happening? Is this a Silverlight bug, or (more likely) am I just missing something?
I think I've figured out the cause of this: I was adding multiple Person objects with the same name. So, if anyone has this issue in the future, make sure all of your objects have unique names!
Person child = person.Children[i];
child.x_PositionTransform.X = person.x_PositionTransform.X;
child.x_PositionTransform.Y = person.x_PositionTransform.Y;
child.Click += new RoutedEventHandler(person_Click);
child.SetValue(Canvas.NameProperty, "child" + objCount++); //!
x_LayoutRoot.Children.Add(child);
you can add different NameProperty before add a child