Usuário com melhor resposta
ArgumentOutOfRangeException was unhandled by user code

Pergunta
-
Esta mensagem esta aparecendo no SelectedIndexChanged Pessoa Juridica juntamente com a seguinte descrição:
O índice estava fora do intervalo. Ele deve ser não-negativo e menor que o tamanho da coleção.
Nome do parâmetro: indexAbaixo as linhas de código:
'' <summary>
''' GRIDVIEW RowDataBound Pessoa Jurídica
''' </summary>
''' <param name="sender"></param>
''' <param name="e"></param>
''' <remarks></remarks>
Protected Sub gvwPJ_RowDataBound(sender As Object, e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gvwPJ.RowDataBound
'Label2.Text = "PAG:" & gvwPJ.PageIndex + 1 & " /" & gvwPJ.PageCount
If e.Row.RowType = DataControlRowType.Header Then
'e.Row.Cells(0).Visible = False
e.Row.Cells(1).Text = "ID"
e.Row.Cells(2).Visible = False
e.Row.Cells(3).Text = "Categoria"
e.Row.Cells(4).Visible = False
e.Row.Cells(5).Text = "Razão Social"
e.Row.Cells(6).Text = "Nome Fantasia"
e.Row.Cells(7).Visible = False
e.Row.Cells(8).Visible = False
e.Row.Cells(9).Visible = False
e.Row.Cells(10).Visible = False
e.Row.Cells(11).Visible = False
e.Row.Cells(12).Visible = False
e.Row.Cells(13).Visible = False
e.Row.Cells(14).Visible = False
e.Row.Cells(15).Visible = False
e.Row.Cells(16).Visible = False
End If
If e.Row.RowType = DataControlRowType.DataRow Then
e.Row.Cells(0).Visible = True
e.Row.Cells(1).Visible = True
e.Row.Cells(2).Visible = False
e.Row.Cells(3).Visible = True
e.Row.Cells(4).Visible = False
e.Row.Cells(5).Visible = True
e.Row.Cells(6).Visible = True
e.Row.Cells(7).Visible = False
e.Row.Cells(8).Visible = False
e.Row.Cells(9).Visible = False
e.Row.Cells(10).Visible = False
e.Row.Cells(11).Visible = False
e.Row.Cells(12).Visible = False
e.Row.Cells(13).Visible = False
e.Row.Cells(14).Visible = False
e.Row.Cells(15).Visible = False
e.Row.Cells(16).Visible = False
End If
End Sub''' <summary>
''' GRIDVIEW SelectedIndexChanged Pessoa Juridica
''' </summary>
''' <param name="sender"></param>
''' <param name="e"></param>
''' <remarks></remarks>
Protected Sub gvwPJ_SelectedIndexChanged(sender As Object, e As EventArgs) Handles gvwPJ.SelectedIndexChanged
limpa()
btnAlterar.Enabled = True
btnExcluir.Enabled = True
btnInserir.Enabled = FalseIf gvwPJ.SelectedRow.Cells(2).Text = "" Then
rblCategoriaCadastro.ClearSelection()
ElseIf gvwPJ.SelectedRow.Cells(2).Text = "Endereço" Then
rblCategoriaCadastro.SelectedIndex = 0
ElseIf gvwPJ.SelectedRow.Cells(2).Text = "Pessoa Jurídica" Then
rblCategoriaCadastro.SelectedIndex = 1
ElseIf gvwPJ.SelectedRow.Cells(2).Text = "Pessoa Física" Then
rblCategoriaCadastro.SelectedIndex = 2
End If
If gvwPJ.SelectedRow.Cells(3).Text = "" Then
rblCategoriaPJ.ClearSelection()
ElseIf gvwPJ.SelectedRow.Cells(3).Text = "Cliente" Then
rblCategoriaPJ.SelectedIndex = 0
ElseIf gvwPJ.SelectedRow.Cells(3).Text = "Prestador" Then
rblCategoriaPJ.SelectedIndex = 1
ElseIf gvwPJ.SelectedRow.Cells(3).Text = "Fornecedor" Then
rblCategoriaPJ.SelectedIndex = 2
End If
txtDataCadasPJ.Text = gvwPJ.SelectedRow.Cells(4).Text
txtRazao.Text = HttpUtility.HtmlDecode(gvwPJ.SelectedRow.Cells(5).Text)
txtFantasia.Text = HttpUtility.HtmlDecode(gvwPJ.SelectedRow.Cells(6).Text)
txtSocio.Text = HttpUtility.HtmlDecode(gvwPJ.SelectedRow.Cells(7).Text)
txtCPFsocio.Text = gvwPJ.SelectedRow.Cells(8).Text
txtDataFunda.Text = gvwPJ.SelectedRow.Cells(9).Text
txtCNPJ.Text = gvwPJ.SelectedRow.Cells(10).Text
txtIE.Text = gvwPJ.SelectedRow.Cells(11).Text
txtDataIniContrato.Text = gvwPJ.SelectedRow.Cells(12).Text
txtDataFinalContrato.Text = gvwPJ.SelectedRow.Cells(13).Text
ddlCNAE.Text = HttpUtility.HtmlDecode(gvwPJ.SelectedRow.Cells(14).Text)
lblCodEndPJ.Text = gvwPJ.SelectedRow.Cells(15).Text
txtObservaPJ.Text = HttpUtility.HtmlDecode(gvwPJ.SelectedRow.Cells(16).Text)
Label3.Text = ""
Label4.Text = ""
End Sub
Respostas
-
Confesso que não consegui achar o problema olhando esse código, o que imaginei que poderia estar acontecendo é na hora da seleção da linha do grid, ao passar pelo Page_Load, o bind estar sendo executado e alterando alguma coisa nas cells do grid. Mas como esse não é o caso achei estranho, o método "limpa()" faz o que?
Rodrigo Reis Ferreira
Microsoft Certified- Marcado como Resposta Wilson Boris segunda-feira, 4 de junho de 2012 18:04
Todas as Respostas
-
Bom dia, verifique por favor o local exato onde o erro foi disparado, coloque um breakpoint no código e faça passo-a-passo (olhe os detalhes da exceção disparada). O erro pode estar em muitos lugares qualquer um desses pontos onde você acessa manualmente o index de uma das células pode disparar esse tipo de erro, por exemplo, se você fizer isso:
e.Row.Cells(16).Visible = False
mas não existir uma posição 16, o erro será disparado.Rodrigo Reis Ferreira
Microsoft Certified- Sugerido como Resposta Cleber H. Neves segunda-feira, 4 de junho de 2012 11:20
-
Boa dia Rodrigo, muito obrigado pelo retorno, fazendo um Breakpoint em Protected Sub gvwPJ_SelectedIndexChanged a mensagem logo aparece na linha
If gvwPJ.SelectedRow.Cells(2).Text = "" Then, mas veja: se retiro essa linha a mensagem aparece na seguinte, se eu retiro a seguinte aparece na outra e assim por diante.
-
Wilson o problema está pq no campo do seu banco de dados tem registros NULL e vc não está fazendo esse filtro na sua consulta, no seu select para esses campos faça assim :
isnull(campo,'valor padrao') as nome
Assim caso o valor no campo para o registo que vc quer esteja null ele jogará o valor padrão e não dará mais erro.
Junior
-
Wilson, se esta ocorrendo em todas as linhas seguintes é porque o número da célula que está sendo acessada é superior ao que de fato existe no SelectedRow, ou seja, digamos que na linha existem 2 células, Cells(0) e Cells(1), então ao tentar acessar Cells(2) vai dar erro, e consequentemente qualquer número superior a esse: Cells(3), Cells(4),....
Faça o seguinte durante o breakpoint coloque o mouse sobre "SelectedRow" e verifique quantas Cells existem.
Rodrigo Reis Ferreira
Microsoft Certified -
-
Faz assim: em cima do SelectedRow clica no + > depois em "base" clica no + > depois no "Cells" clica no + e veja o valor do "Count". O erro ta sendo disparado apenas quando você clica para selecionar alguma linha? Ou no DataBound ja ocorre algum problema? O grid é exibido na tela?
Rodrigo Reis Ferreira
Microsoft Certified -
-
-
Posso sim, vai também do select do grid.
<asp:GridView ID="gvwPJ" runat="server" CellPadding="4" ForeColor="#333333"
GridLines="None" PageSize="5"
ToolTip="Clique em Sel. para validação de endereços, alterações ou exclusões empresas."
Width="543px">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:CommandField ButtonType="Button" SelectText="Selecionar"
ShowSelectButton="True" />
</Columns>
<FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#990000" Font-Bold="True" Font-Size="Small"
ForeColor="White" />
<PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />
<RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
<SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
<SortedAscendingCellStyle BackColor="#FDF5AC" />
<SortedAscendingHeaderStyle BackColor="#4D0000" />
<SortedDescendingCellStyle BackColor="#FCF6C0" />
<SortedDescendingHeaderStyle BackColor="#820000" />
</asp:GridView>Public Class CADASTRO
Inherits System.Web.UI.Page
Dim con As New OleDbConnection
Dim Dadapter As OleDbDataAdapter = New OleDbDataAdapter
Dim DSet As New DataSet
''' <summary>
''' Load com o carregamento dos comandos de todas as Views
''' </summary>
''' <param name="sender"></param>
''' <param name="e"></param>
''' <remarks></remarks>
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
desabilita()
btnInserir.Enabled = False
btnPesquisar.Enabled = False
txtPesquisa.Enabled = False
cargaCategoriaCadastro()
Session.Add("DS", DSet)
DSet = Session.Item("DS")
'......Endereço
cargatipo()
cargaSituacao()
cargaUF()
'.......Pessoa Juridica
cargaCategPJ()
cargaCodCNAE()
cargaDenominaCNAE()
cargaRazaoSocialUA()
cargaRazaoSocialUS()
cargaUAUS()
'....Pessoa Física
cargaSexo()
cargaEstadoCivil()
cargaNumFil()
cargaTipoSangue()
cargaEscola()
cargaVinculoEmprTrab()
cargaRazaoSocialTrab()
cargaRazaoSocialUsu()
cargaUSTrab()
cargaOcupaTrab()
cargaOcupaUsu()
cargaTempoOcupaTrab()
cargaTempoOcupaUsu()
cargaSitOcupTrab()
cargaHistEmpreTrab()
cargaHistEmpreUsu()
cargaCurricTrab()
cargaCurricUsu()
cargaCondAtualUsu()
cargaCondAtualTrab()
End If
End Sub''' <summary>
''' 'Botão Pesquisar conforme a categoria de cadastro
''' </summary>
''' <param name="sender"></param>
''' <param name="e"></param>
''' <remarks></remarks>
Protected Sub btnPesquisarEnd_Click(sender As Object, e As EventArgs) Handles btnPesquisar.Click
Dim con As New OleDbConnection
con.ConnectionString = My.Settings.SIADSConecte
Dim comando As New OleDbCommand
comando.Connection = con
'....
If mtvCadastro.ActiveViewIndex = 0 Then
comando.CommandText = "SELECT * FROM tbCadEndereco WHERE logradouro LIKE '%" + txtPesquisa.Text + "%' ORDER BY codendereco DESC"
If Not con.State = ConnectionState.Open Then
con.Open()
End If
Using dr As OleDbDataReader = comando.ExecuteReader
gvwEnd.DataSource = dr
gvwEnd.DataBind()
dr.Close()
End Using
con.Close()
Label2.Text = ""
'......
ElseIf mtvCadastro.ActiveViewIndex = 1 Then
If TabContainerPJ.ActiveTabIndex = 0 Then
comando.CommandText = "SELECT * FROM tbCadPessoaJuridica B WHERE razaoSocial LIKE '%" + txtPesquisa.Text + "%' ORDER BY codRazaoSocial DESC"
If Not con.State = ConnectionState.Open Then
con.Open()
End If
Using dr As OleDbDataReader = comando.ExecuteReader
gvwPJ.DataSource = dr
gvwPJ.DataBind()
dr.Close()
End Using
con.Close()
Label4.Text = ""
ElseIf TabContainerPJ.ActiveTabIndex = 1 Then
comando.CommandText = "SELECT * FROM tbCadUnidadesAdministrativas WHERE descricao LIKE '%" + txtPesquisa.Text + "%' ORDER BY codUA DESC"
If Not con.State = ConnectionState.Open Then
con.Open()
End If
Using dr As OleDbDataReader = comando.ExecuteReader
gvwUA.DataSource = dr
gvwUA.DataBind()
dr.Close()
End Using
con.Close()
Label6.Text = ""
ElseIf TabContainerPJ.ActiveTabIndex = 2 Then
comando.CommandText = "SELECT * FROM tbCadUnidadesdeServicos WHERE descricao LIKE '%" + txtPesquisa.Text + "%' ORDER BY codUS DESC"
If Not con.State = ConnectionState.Open Then
con.Open()
End If
Using dr As OleDbDataReader = comando.ExecuteReader
gvwUS.DataSource = dr
gvwUS.DataBind()
dr.Close()
End Using
con.Close()
Label8.Text = ""
End If
ElseIf mtvCadastro.ActiveViewIndex = 4 Then
If TabContainerPF.ActiveTabIndex = 0 Then
comando.CommandText = "SELECT * FROM tbCadPessoaFisica WHERE Nome LIKE '%" + txtPesquisa.Text + "%' ORDER BY codigoPF DESC"
If Not con.State = ConnectionState.Open Then
con.Open()
End If
Using dr As OleDbDataReader = comando.ExecuteReader
gvwPF.DataSource = dr
gvwPF.DataBind()
dr.Close()
End Using
con.Close()
Label10.Text = ""
ElseIf TabContainerPF.ActiveTabIndex = 1 Then
comando.CommandText = "SELECT * FROM tbCadPessoaFisica WHERE Nome LIKE '%" + txtPesquisa.Text + "%' ORDER BY codigoPF DESC"
If Not con.State = ConnectionState.Open Then
con.Open()
End If
Using dr As OleDbDataReader = comando.ExecuteReader
gvwPFTrab.DataSource = dr
gvwPFTrab.DataBind()
dr.Close()
End Using
con.Close()
Label12.Text = ""
ElseIf TabContainerPF.ActiveTabIndex = 2 Then
comando.CommandText = "SELECT * FROM tbCadPessoaFisica WHERE Nome LIKE '%" + txtPesquisa.Text + "%' ORDER BY codigoPF DESC"
If Not con.State = ConnectionState.Open Then
con.Open()
End If
Using dr As OleDbDataReader = comando.ExecuteReader
gvwPFUsu.DataSource = dr
gvwPFUsu.DataBind()
dr.Close()
End Using
con.Close()
Label14.Text = ""
End If
End If
End Sub -
Confesso que não consegui achar o problema olhando esse código, o que imaginei que poderia estar acontecendo é na hora da seleção da linha do grid, ao passar pelo Page_Load, o bind estar sendo executado e alterando alguma coisa nas cells do grid. Mas como esse não é o caso achei estranho, o método "limpa()" faz o que?
Rodrigo Reis Ferreira
Microsoft Certified- Marcado como Resposta Wilson Boris segunda-feira, 4 de junho de 2012 18:04
-
Rodrigo, agradeço muito o teu empenho. Neste form eu tenho uma multiview com pode verificar no método limpa() abaixo:
Private Sub limpa()
If mtvCadastro.ActiveViewIndex = 0 Then
cargaMunicipio()
lblCodEnd.Text = ""
rblTipo.ClearSelection()
txtLogra.Text = ""
txtNum.Text = ""
rblSituacao.ClearSelection()
txtBairroLocal.Text = ""
txtTelRes.Text = ""
txtTelCom.Text = ""
txtTelCel.Text = ""
ddlUF.Text = ""
ddlMun.Text = ""
txtEmail.Text = ""
txtHome.Text = ""
txtContato.Text = ""
txtObservaEnd.Text = ""
ElseIf mtvCadastro.ActiveViewIndex = 1 Then
If TabContainerPJ.ActiveTabIndex = 0 Then
cargaCodCNAE()
ddlPJEnd.SelectedIndex = 0
txtRazao.Text = ""
txtFantasia.Text = ""
rblCategoriaPJ.ClearSelection()
txtDataCadasPJ.Text = ""
txtSocio.Text = ""
txtCPFsocio.Text = ""
txtCNPJ.Text = ""
txtIE.Text = ""
txtDataFunda.Text = ""
txtDataIniContrato.Text = ""
txtDataFinalContrato.Text = ""
ddlDenominaCNAE.Text = ""
ddlCNAE.Text = ""
txtObservaPJ.Text = ""
ElseIf TabContainerPJ.ActiveTabIndex = 1 Then
ddlPJEnd0.SelectedIndex = 0
ddlNomeEmpresaUA.Text = ""
txtNomeUA.Text = ""
txtObservaUA.Text = ""
ElseIf TabContainerPJ.ActiveTabIndex = 2 Then
ddlPJEnd1.SelectedIndex = 0
ddlNomeEmpresaUS.SelectedIndex = 0
ddlUnidAdmUS.SelectedIndex = 0
txtNomeUS.Text = ""
txtObservaUS.Text = ""
End If
ElseIf mtvCadastro.ActiveViewIndex = 4 Then
If TabContainerPF.ActiveTabIndex = 0 Then
txtDataCadastroPF.Text = ""
txtNome.Text = ""
txtSobrenome.Text = ""
rblSexo.ClearSelection()
txtNomeMae.Text = ""
txtNomePai.Text = ""
rblEstadoCivil.ClearSelection()
rblNumeroFilhos.ClearSelection()
txtDataNascimento.Text = ""
txtCPF.Text = ""
rblTipoSangue.ClearSelection()
ddlEscolaridade.Text = ""
txtEspecialidade.Text = ""
ElseIf TabContainerPF.ActiveTabIndex = 1 Then
txtRGTrab.Text = ""
txtOrgaoExpTrab.Text = ""
txtDataEmisTrab.Text = ""
txtConselhoClasseTrab.Text = ""
txtNumConsClasseTrab.Text = ""
ddlRazaoSocialTrab.Text = ""
txtDataAdmissaoTrab.Text = ""
rblVinculoEmpregaTrab.ClearSelection()
ddlUnidadeServTrab.Text = ""
ddlOcupacaoTrab.Text = ""
ddlTempoOcupacaoTrab.Text = ""
rblSituacaoOcupaTrab.ClearSelection()
ddlHistoricoEmpregTrab.Text = ""
rblCurriculoTrab.ClearSelection()
rblCondicaoAtualTrab.ClearSelection()
txtObservaTrab.Text = ""
ElseIf TabContainerPF.ActiveTabIndex = 2 Then
txtRGUsu.Text = ""
txtOrgaoExpUsu.Text = ""
txtDataEmisUsu.Text = ""
txtConselhoClasseUsu.Text = ""
txtNumConsClasseUsu.Text = ""
ddlRazaoSocialUsu.Text = ""
ddlOcupacaoUsu.Text = ""
ddlTempoOcupacaoUsu.Text = ""
ddlHistoricoEmpregUsu.Text = ""
rblCurriculoUsu.ClearSelection()
rblCondicaoAtualUsu.ClearSelection()
txtObservaUsu.Text = ""
End If
End If
End Sub -
Rodrigo! Parabénsssssss. Voce comentou: "o bind estar sendo executado e alterando alguma coisa nas cells do grid." Veja abaixo:
''' <summary>
''' Direciona para cada View conforme as categorias de cadastro: Endereço, Pessoa Jurídica ou Pessoa Física
''' </summary>
''' <param name="sender"></param>
''' <param name="e"></param>
''' <remarks></remarks>
Protected Sub RadioButtonList1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles rblCategoriaCadastro.SelectedIndexChanged
btnInserir.Enabled = True
btnPesquisar.Enabled = True
txtPesquisa.Enabled = True
If rblCategoriaCadastro.SelectedIndex = 0 Then
mtvCadastro.ActiveViewIndex = 0
gvwEnd.DataSource = Nothing
gvwEnd.DataBind()
ElseIf rblCategoriaCadastro.SelectedIndex = 1 Then
mtvCadastro.ActiveViewIndex = 1
TabContainerPJ.ActiveTabIndex = 0
CargaddlPJEnd()
CargaddlPJEnd0()
CargaddlPJEnd1()
gvwPJ.DataSource = Nothing
gvwPJ.DataBind()
ElseIf rblCategoriaCadastro.SelectedIndex = 2 Then
mtvCadastro.ActiveViewIndex = 4
TabContainerPF.ActiveTabIndex = 0
CargaddlPFEnd()
gvwPF.DataSource = Nothing
gvwPF.DataBind()
End If
End SubProtected Sub TabContainerPJ_ActiveTabChanged(sender As Object, e As EventArgs) Handles TabContainerPJ.ActiveTabChanged
If TabContainerPJ.ActiveTabIndex = 0 Then
gvwPJ.DataSource = Nothing
gvwPJ.DataBind()
ElseIf TabContainerPJ.ActiveTabIndex = 1 Then
gvwUA.DataSource = Nothing
gvwUA.DataBind()
ElseIf TabContainerPJ.ActiveTabIndex = 2 Then
gvwUS.DataSource = Nothing
gvwUS.DataBind()
End If
End SubProtected Sub TabContainerPF_ActiveTabChanged(sender As Object, e As EventArgs) Handles TabContainerPF.ActiveTabChanged
If TabContainerPF.ActiveTabIndex = 0 Then
gvwPF.DataSource = Nothing
gvwPF.DataBind()
ElseIf TabContainerPF.ActiveTabIndex = 1 Then
gvwPFTrab.DataSource = Nothing
gvwPFTrab.DataBind()
ElseIf TabContainerPF.ActiveTabIndex = 2 Then
gvwPFUsu.DataSource = Nothing
gvwPFUsu.DataBind()
End If
End Sub -
Rodrigo! Parabénsssssss. Voce comentou: "o bind estar sendo executado e alterando alguma coisa nas cells do grid." Veja abaixo:
''' <summary>
''' Direciona para cada View conforme as categorias de cadastro: Endereço, Pessoa Jurídica ou Pessoa Física
''' </summary>
''' <param name="sender"></param>
''' <param name="e"></param>
''' <remarks></remarks>
Protected Sub RadioButtonList1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles rblCategoriaCadastro.SelectedIndexChanged
btnInserir.Enabled = True
btnPesquisar.Enabled = True
txtPesquisa.Enabled = True
If rblCategoriaCadastro.SelectedIndex = 0 Then
mtvCadastro.ActiveViewIndex = 0
gvwEnd.DataSource = Nothing
gvwEnd.DataBind()
ElseIf rblCategoriaCadastro.SelectedIndex = 1 Then
mtvCadastro.ActiveViewIndex = 1
TabContainerPJ.ActiveTabIndex = 0
CargaddlPJEnd()
CargaddlPJEnd0()
CargaddlPJEnd1()
gvwPJ.DataSource = Nothing
gvwPJ.DataBind()
ElseIf rblCategoriaCadastro.SelectedIndex = 2 Then
mtvCadastro.ActiveViewIndex = 4
TabContainerPF.ActiveTabIndex = 0
CargaddlPFEnd()
gvwPF.DataSource = Nothing
gvwPF.DataBind()
End If
End SubProtected Sub TabContainerPJ_ActiveTabChanged(sender As Object, e As EventArgs) Handles TabContainerPJ.ActiveTabChanged
If TabContainerPJ.ActiveTabIndex = 0 Then
gvwPJ.DataSource = Nothing
gvwPJ.DataBind()
ElseIf TabContainerPJ.ActiveTabIndex = 1 Then
gvwUA.DataSource = Nothing
gvwUA.DataBind()
ElseIf TabContainerPJ.ActiveTabIndex = 2 Then
gvwUS.DataSource = Nothing
gvwUS.DataBind()
End If
End SubProtected Sub TabContainerPF_ActiveTabChanged(sender As Object, e As EventArgs) Handles TabContainerPF.ActiveTabChanged
If TabContainerPF.ActiveTabIndex = 0 Then
gvwPF.DataSource = Nothing
gvwPF.DataBind()
ElseIf TabContainerPF.ActiveTabIndex = 1 Then
gvwPFTrab.DataSource = Nothing
gvwPFTrab.DataBind()
ElseIf TabContainerPF.ActiveTabIndex = 2 Then
gvwPFUsu.DataSource = Nothing
gvwPFUsu.DataBind()
End If
End Sub -
hum..entendo, então é o DataBind() que esta fazendo perder a seleção, para limpar o grid bastaria atribuir o null e dar o Bind mesmo, porém isso não poder ser feito após o Grid disparar algum comando(no seu caso de Select).
Rodrigo Reis Ferreira
Microsoft Certified