ASPxGridview Change Default value in inline EditForm - vb.net

I'm trying to change the value in an editform before it becomes visible to the user. However the aspxgridview is always overwriting this.
This is my solution:
Protected Sub ASPxGridView_ItemList_HtmlRowCreated(ByVal sender As Object, ByVal e As DevExpress.Web.ASPxGridView.ASPxGridViewTableRowEventArgs) Handles ASPxGridView_Items.HtmlRowCreated
If (e.RowType = GridViewRowType.EditForm) Then
Dim ASPxTextbox_Number As ASPxTextBox = TryCast(TryCast(sender, ASPxGridView).FindEditFormTemplateControl("ASPxTextbox_Number"), ASPxTextBox)
ASPxTextbox_Number.Text = "99"
End If
End Sub

Please refer to the How to update an ASPxGridView DataSource if the initial values are set programmatically in the HtmlRowCreated event example in this regard.

Related

VB - Gridview style after index changed

i've a gridview with pagesize=10, when i load the page and bind grid i've the correct style applied (checkbox cheched or no), but when i go to second page i can't apply the style (checkbox always not checked) and if i came back to the first page i haven't the correst style applied.
At the page load i store all checkbox states into a dictonary to check when i bind the grid.
Public listaCheckbox As New Dictionary(Of Integer, Boolean)
I tried to apply a style to the first row to understand where I'm wrong but it's always the same thing.
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
RecuperaCheckbox() 'to store all checkbox value into listaCheckbox, it works
If IsPostBack = False Then
Me.BindGrid2()
End If
End Sub
Protected Sub OnPageIndexChanging(sender As Object, e As GridViewPageEventArgs) Handles GridViewListaEsp.PageIndexChanging
GridViewListaEsp.PageIndex = e.NewPageIndex
Me.BindGrid2()
End Sub
Private Sub BindGrid2()
Query = "SELECT ...
FROM ...;"
List.SelectCommand = Query
GridViewListaEsp.DataBind()
For i = 0 To GridViewListaEsp.Rows.Count - 1
Dim chk As CheckBox = GridViewListaEsp.Rows(i).FindControl("chkOnOff")
Dim id_azienda As String = GridViewListaEsp.Rows(i).Cells(1).Text
listaCheckbox.TryGetValue(id_azienda, chk.Checked) 'works only at the first page load
Next
GridViewListaEsp.Rows(0).Attributes.Add("style", "background-color:aqua") 'works only at the first page load
End Sub
I found the solution:
to bind grid i used the command:
list.SelectCommand = Query
this was working for all thing except for the application of the style after index changing.
I changed part of code with this:
cmdExist = New SACommand(szPrintf(Query), con)
drExist = cmdExist.ExecuteReader
Dim DT As New DataTable
DT.Load(drExist)
GridViewListaEsp.DataSource = DT
GridViewListaEsp.DataBind()
And now i can apply new style after change index page!

vb.net ComboBox Text Changing When Left

I'm having an issue with my ComboBoxes whereby if I type into it to get a value & then tab out the Text changes to the first item in the list with the first letter typed.
I have:
AutoCompleteMode set to SuggestAppend
AutoCompleteSource set to ListItems
DropDownStyle set to DropDownList
I add the items for the ComboBox in the Load event of the Form the ComboBox is on.
e.g. the below is code from a Load event where I populate a ComboBox that I have set up as below.
`Me.ComboBox1.Text = ""
Me.ComboBox1.Items.Add("a")
Me.ComboBox1.Items.Add("aaa")
Me.ComboBox1.Items.Add("combo")
Me.ComboBox1.Items.Add("combobox")
Me.ComboBox1.Items.Add("combobox test")
Me.ComboBox1.Items.Add("common")
Me.ComboBox1.Items.Add("common dialog")`
After running the code, if I select the ComboBox1 & type in common - common is selected in ComboBox1 but if I leave ComboBox1 the Text reverts to combo.
It gets a bit stranger as if I user the below code in the ComboBox1_Leave event procedure it throws common:
MsgBox(ComboBox1.Text)
I've also tried assigning the value of Text to a string in the ComboBox1_KeyUp event procedure & then assign that to ComboBox1.Text in the ComboBox1_Leave event procedure but that doesn't do anything.
If I put a the above MsgBox code before assigning the strings value to ComboBox1.Text then the Text value does revert to Common but this is isn't a practical solution.
I've also noticed that if I hit Enter before hitting tab it retains the correct value but again I'm don't think this is a particularly practical solution.
Does anyone have any idea what's going on here & how I can fix it?
It is absolutely necessary to have the DropDownStyle set to DropDownList?
Because if you set DropDownStyle to DropDown the selected value will be retained when you press tab or lose the focus.
If it's absolutely necessary to have it that way, you could try this.
Public Class Form2
Dim selectedTextForCombo As String = ""
Private Sub Form2_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Me.ComboBox1.Text = ""
Me.ComboBox1.Items.Add("a")
Me.ComboBox1.Items.Add("aaa")
Me.ComboBox1.Items.Add("combo")
Me.ComboBox1.Items.Add("combobox")
Me.ComboBox1.Items.Add("combobox test")
Me.ComboBox1.Items.Add("common")
Me.ComboBox1.Items.Add("common dialog")
End Sub
Private Sub ComboBox1_LostFocus(sender As Object, e As System.EventArgs) Handles ComboBox1.LostFocus
ComboBox1.SelectedItem = selectedTextForCombo
'This is just for a visualization of your issue
'Label1.Text = selectedTextForCombo
End Sub
Private Sub ComboBox1_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
selectedTextForCombo = ComboBox1.Text
'This is just for a visualization of your issue
'Label1.Text = selectedTextForCombo
End Sub
End Class
Warning:
This example works with the tab action.
If the users writes something that doesn't exist like "commun" the
selected value will end up being the visually selected value, in this
case: "common"

Passing Variable from Windows form to Modal

Windows Forms, VB. I have searched the web for the correct answer to this and no dice. Either they are missing on what I am trying to accomplish or are in CSHARP making it harder for me to see what they are doing. I have a need to pass a record Id from the main windows form into a modal Dialog Load Event.. I have tried throwing a with param in but then I have to change the Load event params and vb flags it.. I am trying to pass the value of _CurrentProp which is an integer into the dialog. This is the dialog constructor and the load event inside that dialog..
Private Sub PropertySettingsMenuClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PropertyDetailsToolStripMenuItem.Click
Dim _propertSettings As New PropertySettingsWindow()
_propertSettings.ShowDialog()
End Sub
Private Sub PropertySettings_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim _properties As New List(Of property_info)
_properties = db.property_info.ToList
For Each a In _properties
If Not p_settingsCityList.Items.Contains(a.city) Then
p_settingsCityList.Items.Add(a.city)
End If
Next
For Each b In _properties
If Not p_settingsPropertyList.Items.Contains(b.property_Name) Then
p_settingsPropertyList.Items.Add(Convert.ToString(b.idProperties) + " -- " + b.property_Name)
End If
Next
p_settingsZipCode.ReadOnly = True
p_settings_Address.ReadOnly = True
p_settings_PropertyName.ReadOnly = True
End Sub
I am going to simply assign the value to a global variable inside the PropertySettings Class but everything I try seems to fail in one way or another... Any ideas...
Add a public property RecordID to your dialog window, then open the dialog like this
Dim _propertSettings As New PropertySettingsWindow()
_propertSettings.RecordID = 15
_propertSettings.ShowDialog()
In the dialog form you can simply access the record id with
_properties = db.property_info_by_id(RecordID).ToList
Starting with .NET Framework 4.0, you can use auto-implemented properties
Public Property RecordID As Integer
With previous versions you would have to write
Private _recordID As Integer
Property RecordID As Integer
Get
Return _recordID
End Get
Set(ByVal value As Integer)
_recordID = value
End Set
End Property

Value of global variable won't change

I have a variable whose scope needs to be global, because it needs to be called in a function as well as in a button press. So I declared the variable in a Module so it would be global.
The problem is that the value of this variable needs to be equal to the value of the text property of a textbox in the form.
Here you can download the VB.net demonstration of my problem: http://db.tt/DDxQJDXl
Below is an explanation of what happens
You enter a string into the textbox, in this case I entered "Hello". Then you click the button and it displays what you wrote.
You click OK in that message box and change the value in the textbox. In this case I changed it to "Goodbye". Then I hit the button again, but the variable did not change values and the messagebox displays "Hello" again.
Here is the entire source code:
Module Module1
Public strDataValue = frmTest.txtDataValue.Text
End Module
Public Class frmTest
Private Sub btnTest_Click(sender As System.Object, e As System.EventArgs) Handles btnTest.Click
MsgBox(strDataValue)
End Sub
End Class
Note: This is just a demonstration of a problem I'm having in a much larger program so the variable does have to be global.
You need to set the value of the field to the new value in the TextBox:
Private Sub btnTest_Click(sender As System.Object, e As System.EventArgs) Handles btnTest.Click
strDataValue = txtDataValue.Text
MsgBox(strDataValue)
End Sub
The field will not change values by itself.
The value of strDataValue won't automatically change when txtDataValue.Text changes. You need to update strDataValue manually, either when the textbox loses focus, or when you click the Test button.
You could also have a public property, which automatically returns the actual value as long as the form is open.
Public ReadOnly Property DataValue() As String
Get
Return frmTest.txtDataValue.Text
End Get
End Property
You need to assign value of txtDataValue.Text to your variable strDataValue in better performance
Using of Timer object or TextChenged event not recommended
Any change of txtDataValue.Text can assign after end of editing action
for me best solution: Leave or LostFocus events
Private Sub txtDataValue_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtDataValue.Leave
strDataValue = txtDataValue.Text
End Sub

GridView1.SelectedRow returning nothing

My problem is that in the below code, the SelectedRow property returns nothing. I manually bind items to GridView at runtime and autogeneratecolumns and autogenerateselectbutton properties are true.
I think the problem is about having a PostBack when the Select command is clicked.
Thanks a lot.
Protected Sub GridView1_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles GridView1.RowCommand
Session("ContactID") = GridView1.SelectedRow.Cells(0).Text()
Response.Redirect("~/ContactAddress.aspx")
End Sub
The row you want is accessible via e (the GridViewCommandEventArgs parameter), specifically the value of e.CommandArgument which will have the row index :
From here :
To determine the index of the row that
raised the event, use the
CommandArgument property of the event
argument that is passed to the event.
The ButtonField class automatically
populates the CommandArgument property
with the appropriate index value. For
other command buttons, you must
manually set the CommandArgument
property of the command button. For
example, you can set the
CommandArgument to <%#
Container.DataItemIndex %> when the
GridView control has no paging
enabled.
The selected row is in the GridViewCommandEventArgs parameter.
Besides adding the CommandArgument, you need to change your code to the following.
Protected Sub GridView1_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles GridView1.RowCommand
Dim rowNumber As Integer = e.CommandArgument
Dim ContactId As Integer = GridView1.Rows(rowNumber).Cells(0).Text
Session("ContactID") = ContactId
Response.Redirect("~/ContactAddress.aspx")
End Sub