Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.

GridViewControl - Index was out of range

[es] :: .NET :: GridViewControl - Index was out of range

[ Pregleda: 379 | Odgovora: 2 ]

Postavi temu Odgovori

Autor

Pretraga teme: Traži
Markiranje Štampanje RSS

KizaBG

Član broj: 169491
Poruke: 94
*.adsl-1.sezampro.yu.



Profil

icon GridViewControl - Index was out of range21.05.2008. u 12:49

Kako da izbegnem ovu gresku ?

Naime, imam DataGridView kontrolu, koju punim iz storovane procedure. I sve radi OK, dok ne kliknem mousem na naslove kolona (rowHeader).

U tom slucaju program pukne sa porukom 'Index was out of range". Evo koda

private void dgvOglasi_CellClick(object sender, DataGridViewCellEventArgs e)
{
try
{
int OglasZaPosaoID = (int)dgvOglasi.SelectedRows[0].Cells["OglasZaPosaoID"].Value; <-- ovde pukne

Jasno mi je i zasto puca: jer, OglasZaPosaoID ocekuje integer, a dobije neku bezveze vrednost.

E sad, kako da to handlujem ?


10x thanks in advance

21.05.2008. u 12:49 

Pharos
Pančevo

Član broj: 20664
Poruke: 975
..et.174.106.194.in-addr.arpa.



Profil

icon Re: GridViewControl - Index was out of range21.05.2008. u 13:37
Puca ti zato što nemaš selektovan red (SelectedRows.Count = 0).
Ispitaj prvo taj uslov pa onda radi obradu:
Code:

if(dgvOglasi.SelectedRows.Count == 1)
{
   int OglasZaPosaoID = (int)dgvOglasi.SelectedRows[0].Cells["OglasZaPosaoID"].Value
   ...
}

77 77 77 2E 65 73 6E 69 70 73 2E 63 6F 6D
21.05.2008. u 13:37 

KizaBG

Član broj: 169491
Poruke: 94
*.adsl-1.sezampro.yu.



Profil

icon Re: GridViewControl - Index was out of range21.05.2008. u 17:06
@Pharos: puno hvala. To je to !!

21.05.2008. u 17:06 

[es] :: .NET :: GridViewControl - Index was out of range

[ Pregleda: 379 | Odgovora: 2 ]

Postavi temu Odgovori

Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.