I have a VB.NET web project where I use DevExpress 20.1 version
I’m creating a grid which is empty in the first time and when a line is added grdVariablesFiltro_HtmlDataCellPrepared
function is launched.
Depending of the type, the cell type od the columns VALOR
and CONDICION
are also changing.
<dx:ASPxGridView ID="grdVariablesFiltro"
ClientInstanceName="grdVariablesFiltro" Visible="true"
EnableCallBacks="true" SettingsResizing-ColumnResizeMode="Control"
KeyFieldName="ID_VARIABLE" runat="server" EnableViewState="true"
OnHtmlDataCellPrepared="grdVariablesFiltro_HtmlDataCellPrepared">
<Settings HorizontalScrollBarMode="Auto"
VerticalScrollBarMode="Auto"
VerticalScrollBarStyle="Standard"
ShowFilterBar="Visible" ShowFilterRow="true"
ShowFilterRowMenu="true" ShowHeaderFilterButton="true"/>
<SettingsPager PageSize="10">
<PageSizeItemSettings Visible="true" ShowAllItem="true" />
</SettingsPager>
<SettingsBehavior AllowSort="true" AllowDragDrop="true"
AllowSelectByRowClick="true" AllowSelectSingleRowOnly="false"
EnableCustomizationWindow="false" />
<Columns>
<dx:GridViewCommandColumn HeaderStyle-BackColor="White" ShowSelectCheckbox="true" SelectAllCheckboxMode="AllPages" HeaderStyle-HorizontalAlign="Center" Width="60"/>
<dx:GridViewDataTextColumn FieldName="ID_VARIABLE" Width="10%" meta:resourcekey="colIdVariable" CellStyle-HorizontalAlign="Left"/>
<dx:GridViewDataTextColumn FieldName="SECCION" Width="10%" meta:resourcekey="colSeccion" CellStyle-HorizontalAlign="Left"/>
<dx:GridViewDataTextColumn FieldName="APARTADO" Width="10%" meta:resourcekey="colApartado" CellStyle-HorizontalAlign="Left"/>
<dx:GridViewDataTextColumn FieldName="DESC_VARIABLE" Width="10%" meta:resourcekey="colDescVariable" CellStyle-HorizontalAlign="Left"/>
<dx:GridViewDataTextColumn FieldName="CLAVERO" Width="10%" meta:resourcekey="colClavero" CellStyle-HorizontalAlign="Left"/>
<dx:GridViewDataTextColumn FieldName="CONDICION" Width="10%" meta:resourcekey="colCondicion" CellStyle-HorizontalAlign="Left"/>
<dx:GridViewDataTextColumn FieldName="VALOR" Width="10%" meta:resourcekey="colValor" CellStyle-HorizontalAlign="Left" >
<EditItemTemplate>
<dx:ASPxTextBox ID="txtValor" runat="server" Width="100%" Text='<%# Bind("VALOR") %>'>
</dx:ASPxTextBox>
</EditItemTemplate>
</dx:GridViewDataTextColumn>
</Columns>
</dx:ASPxGridView>
Protected Sub grdVariablesFiltro_HtmlDataCellPrepared(sender As Object, e As ASPxGridViewTableDataCellEventArgs)
If e.DataColumn.FieldName = "ID_VARIABLE" Then 'Obtenemos la variable al que le estamos asignando el tipo de celda
If e IsNot Nothing Then
If e.CellValue IsNot Nothing Then
variableAAnadir = e.CellValue.ToString()
End If
End If
ElseIf e.DataColumn.FieldName = "VALOR" Or e.DataColumn.FieldName = "CONDICION" Then
Dim tipoVariable As Integer = VariablesDAL.GetTipoUsuarioVariable(variableAAnadir)
If e.DataColumn.FieldName = "VALOR" Then
gestionarColumnaValor(e, tipoVariable)
Else
gestionarColumnaCondicion(e, tipoVariable) 'Segun el tipo de dato ponemos unas condiciones u otras
End If
End If
End Sub
'Gestiona la columna de valor segun el tipo
Protected Sub gestionarColumnaValor(e As ASPxGridViewTableDataCellEventArgs, tipoVariable As Integer)
If tipoVariable = 3 Then 'TEXTO
Dim textBox As New ASPxTextBox()
textBox.Text = e.CellValue.ToString()
e.Cell.Controls.Add(textBox)
ElseIf tipoVariable = 1 Or tipoVariable = 2 Then 'NUMERO
Dim spinEdit As New ASPxSpinEdit()
'spinEdit.Value = Convert.ToDecimal(e.CellValue)
spinEdit.ReadOnly = False
e.Cell.Controls.Add(spinEdit)
ElseIf tipoVariable = 101 Then 'SI NO
Dim comboBox As New ASPxComboBox()
comboBox.Items.Add("SI")
comboBox.Items.Add("NO")
'comboBox.SelectedItem = comboBox.Items.FindByText(e.CellValue.ToString())
e.Cell.Controls.Add(comboBox)
Else 'TIPOS DE USUARIO
Dim listaValores As List(Of String) = New List(Of String)()
'Leemos la lista de tipos
listaValores = VariablesDAL.GetValoresTipoUsuario(tipoVariable)
If listaValores.Count > 0 Then
Dim comboBox As New ASPxComboBox()
'Recorremos la lista para rellenar el combo
For Each valor In listaValores
comboBox.Items.Add(valor)
Next
e.Cell.Controls.Add(comboBox)
End If
End If
End Sub
'Gestiona la columna de condicion segun el tipo.
Protected Sub gestionarColumnaCondicion(e As ASPxGridViewTableDataCellEventArgs, tipoVariable As Integer)
Dim comboBox As New ASPxComboBox()
If tipoVariable = 1 Or tipoVariable = 2 Then 'NUMERICO
comboBox.Items.Add("=")
comboBox.Items.Add("!=")
comboBox.Items.Add("<")
comboBox.Items.Add(">")
e.Cell.Controls.Add(comboBox)
Else
comboBox.Items.Add("=")
comboBox.Items.Add("!=")
e.Cell.Controls.Add(comboBox)
End If
comboBox.SelectedIndex = 0 ' Esto selecciona el primer elemento que es "="
e.Cell.Controls.Add(comboBox)
End Sub
Then when the user changes the value of some of the editing columns, I want to receive the changed value. Can be at the moment or also when pressing a button.
How I can achieve this?
I have tried using onrowupdating and some other event launchers but I can’t achieve to go to VB.
Oier is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.