Jump to content

Recommended Posts

Posted

boas pessoal

a minha duvida é a seguinte, eu tenho um datagridview, preenchido com varios registos. e a chave primaria dos registos sao dois campos (Cod, Ano)., e tenho duas text box, uma para inserir o cod e outra para inserir o ano, e ao clicar no botao ok eu queria que o registo que tivesse por exemplo o Cod=1 e o ano=2010 ficasse selecionado(com a cor azul por cima).

mas ja estive a pesquisar e nao encontro  :wallbash:

alguem me pode ajudar?

Posted

Podes utilizar um ciclo For e percorrer as linhas, testando as colunas em questão.

Quando encontrasse, passava a propriedade Selected da row para True.

Sérgio Ribeiro


"Great coders aren't born. They're compiled and released"
"Expert coders do not need a keyboard. They just throw magnets at the RAM chips"

Posted

solução:

For r = 0 To DGridCab.Rows.Count - 1
                    If DGridCab.Rows(r).Cells(0).Value = Ano And DGridCab.Rows(r).Cells(1).Value = Cod Then
                        DGridCab.Rows(r).Selected = True
                    End If
                Next r
Posted

Correção á solução:

For r = 0 To DGridCab.Rows.Count - 1
                If DGridCab.Rows(r).Cells(0).Value = Ano And DGridCab.Rows(r).Cells(1).Value = Cod Then
                    'DGridCab.Rows(r).Selected = True
                    DGridCab.Rows(r).Cells(0).Selected = True
                    Enche_Form()
                    TXTOrcamCod.Text = ""
                    TXTOrcamAno.Text = ""
                Else
                    Cont = Cont + 1
                End If
            Next r

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.