Accessing RadListBox Items in Code-Behind - vb.net

I have the following RadListBox:
<telerik:RadListBox ID="AttachmentsRadListBox" CheckBoxes ="true" runat="server" />
It is located in a RadWindow, therefore I am populating it through the following code which is only called when RadWidnow becomes visible:
AttachmentsRadListBox.DataSource = AttachDT
AttachmentsRadListBox.DataTextField = "DocumentPath"
AttachmentsRadListBox.DataValueField = "DocumentID"
AttachmentsRadListBox.DataBind()
For Each item As RadListBoxItem In AttachmentsRadListBox.Items
item.Checked = True
Next
So far so good, the RadListBox is populated and all the items are checked.
Now, there is a Save button on the RadWindow when pressed before closing the window I am trying to read the checked items in the AttachmentsRadListBox (Since the user might have changed the status of the checked items). But every effort on reading the items has failed, for example on the Save button click I have the following:
Dim test As Integer = AttachmentsRadListBox.Items.Count // THIS IS ZERO
For Each item As RadListBoxItem In AttachmentsRadListBox.Items // THERE ARE NO ITEMS
If Not item.Checked Then
Dim DocumentIDToDelete As Integer = item.Value
End If
Next
Why is that the last piece of code does not behave as I hope? The AttachmentsRadListBox is not being bounded again through the postback. The only time that it is bounded is when the RadWindow appears. Then the Save button on the RadWindow obviously creates a postback but I don't understand why AttachmentsRadListBox contains no item at that point.

Since you create the AttachmentsRadListBox dynamically, do you recreate it on subsequent postbacks? It is, in the end, a server control, so you need to make sure it is recreated, because otherwise ASP will destroy it upon a subsequent postback.
To see how you can access controls in the ContentTemplate of a RadWindow you can also examine this article: http://www.telerik.com/help/aspnet-ajax/window-controls-container.html.

Related

VB.net how to get the value from my user control textbox

I do have a project for daily monitoring, and I have a problem getting the text from my textbox wherein my textbox is in my usercontrol.
the scenario would be, if I click the show button, the userControl.vb would be called in my panel and I dont have a problem putting up userControl.vb to my panel, if I click save button which will check if all fields are fill-up before saving the data. I would save as normal and wont check my panel where I load up my userControl.vb
this my snippet project tree:
DXApplication
|_My Porject
|_User Control <folder>
|_userControl.vb <user control form>
|_frmMainActivity <winForm>
here is my code for loading the userControl in my Panel
Friend ctrlUser As UserControl
ctrlUser = New userControlx
ctrlUser.Dock = DockStyle.Top
pnlActivity.Controls.Clear()
pnlActivity.Controls.Add(ctrlUser)
here is code for calling the textbox from userControl from another sub to check if the code can get the text.
*edited the userControl should be userControlx*
Dim uc As New userControlx
Msgbox(uc.txtLatitude.text)
when i hit the trigger button to show what text i put on my textbox i would return msgbox with empty string.
Any suggestion? where did I go wrong on calling the value of the textbox?
I've tried using:
Dim uc As New userControlx
uc.txtLongitude.text = "Test Text"
msgbox(ux.txtLongitude.txt)
It will return the Test Text, But in my UI the textbox that is loaded is empty.
in the trigger button you create a new instance of userControl, thats why the content of your textbox is emtpy
instead use
Msgbox(ctrlUser.txtLatitude.text)

Can't see dropdown items in Datagridviewcomboboxcell

I have created Datagridviewcomboboxcells as follows, each of which have 2-3 items.
I'm able to see the Datagridviewcomboboxcells with the appropriate values inside the comboboxcell, but I'm not able to see the dropdown list when i click on the comboboxcell.
Should I write a separate event handler to display the dropdown list ? Does it not dropdown by default ?
Dim Dgv2cb_ColdStart As New DataGridViewComboBoxCell
Dgv2cb_ColdStart.Items.Add("C:\pd_DelAll.pl")
Dgv2cb_ColdStart.Items.Add("No Cold Start")
dgv2.Rows.Add("ColdStart")
dgv2.Rows(rowIndex).Cells(1) = Dgv2cb_ColdStart
If temp_profile.ColdStart = "" Then
dgv2.Rows(rowIndex).Cells(1).Value = Dgv2cb_ColdStart.Items(1)
Else
dgv2.Rows(rowIndex).Cells(1).Value = Dgv2cb_ColdStart.Items(0)
End If
Surprising thing is the same code on another backup of the project works, but that is an older version that i can't use now.
I'm not able to reproduce the error, as to what is causing the dropdown not to occur.

Caliburn.micro propertychanged problem in a view

I use Caliburn.Micro for my Silverlight application.
I have a view/viewmodel to create a new Item.
On the view there is one combobox.
The first time I open the view , fill in all fields, the Item is saved correctly.
The second time I open the view, fill in all fields, all teh values of them are changed in the object, except the value of the combobox, this property of Item stays 0 (it's an integer).
Any ideas why this is? I think the Caliburn framework is doing something weird.
thanks,
Filip
The code to open the view was:
EventAggreg.EventAgg.Publish(new ObjectDetailEvent() { ObjectDetail = new ObjectDTO() });
I replaced it with:
EventAggreg.EventAgg.Publish(new ObjectDetailEvent() { ObjectDetail = new ObjectDTO { LandId = 0 } });
LandId is the property bound to the combobox.
So when this is filled in by default, teh notify works perfect every time.

Checked ToolStrip Submenu Items

I'm trying to create a menu in VB.Net where one item in the menu has a submenu that sprouts off to the side when the user hovers over it. In other words, a completely ordinary submenu that everyone's used a million times.
My main menu items are of class ToolStripMenuItem. I can get close to the behavior I want by using the item's "DropDown" member. This creates the submenu behavior correctly, but I also need to be able to check and uncheck the items in the submenu. I've set the submenu items' "CheckOnClick" property to True, but checkboxes are still not displayed when I run the program.
Is it possible to get this behavior? Is it possible with ToolStripMenuItem?
Here's the code I currently have, which gets close, but doesn't give me checkboxes:
Dim mainItem As ToolStripMenuItem = New ToolStripMenuItem()
mainItem.Text = "Click For Submenu"
Dim subMenu As ToolStripDropDown = New ToolStripDropDown()
For Each item As ToolStripMenuItem In listOfItems
item.CheckOnClick = True
subMenu.Items.Add(item)
Next
mainItem.DropDown = subMenu
Try getting rid of that subMenu variable and change the code this way:
For Each mi As ToolStripMenuItem In listOfItems
mi.CheckOnClick = True
mainItem.DropDownItems.Add(mi)
Next

vb.net tabpage using a form for tabpanels issues

I have a simple vb.net form a tabpanel strip, and then a seperate form which is loaded for the tabpage.
Here is the code for the button that dynamically creates new tabs:
Dim tempTab As New TabPage
initTab(tempTab)
xt.TabPages.Add(tempTab)
xt.SelectedIndex = xt.TabCount - 1
Here is the code for the "initTab":
Dim tmpTab As New MainTab
tmpTab.Dock = DockStyle.Fill
tmpTab.Panel1.Dock = DockStyle.Fill
tab.Controls.Add(tmpTab)
tab.Text = "Untitled"
tab.Name = " "
I can easily set the focus of any tab by entering following which sets the focus for example to the last tab:
xt.SelectedIndex = xt.TabCount - 1
Now the issue is, how can I set the focus to a textbox on the custom form (in my example labeled "MainTab")? I've tried virtually everything I can google and I can't seem to find any example of how to setfocus or even set/get anything from the MainTab form.
Anyone can help me?
Erm, turning a form into a child control takes some surgery. You have to set its TopLevel property to false, hide the border, make it visible. I don't see it in the code snippet, is MainTab actually a form?
Anyhoo, you cannot use the Focus() method on a control until it is visible. Odds are good that it isn't visible yet in your code snippet. Use the Select() method instead. Say:
tmpTab.TextBox1.Select()
Or just set the TabIndex property of the first control that should get the focus to 0 in the designer.
xt.Controls(xt.SelectedIndex).Controls("TEXTBOXNAME").Focus()
Just make sure that you set the Name property of the textbox you want to have focus (in this case the name would be TEXTBOXNAME) if you do it like this.