Problem with combobox,selectedvalue

R

Ricardo Luceac

Hi all...

I have the following code:

protected override void OnLoad(EventArgs e)
{
_presenter.OnViewReady();
base.OnLoad(e);
lProfs=_presenter.getProfs();
cbbProf.DataSource = lProfs;
cbbProf.ValueMember = "cpf";
cbbProf.DisplayMember="nome";
}

So when the view loads it populates my combobox.
Then when I select a order id and click load, executes the following
method:

private void btnCarrega_Click(object sender, EventArgs e)
{
int ped = Convert.ToInt32(txtPedido.Text);
if (_presenter.existePedido(ped))
{
lnew = _presenter.getLaudo(ped);
btnGrava.Enabled = true;
cbbProf.Enabled = true;
rtbLaudo.Enabled = true;
rtbLaudo.Rtf= lnew.Texto;
cbbProf.SelectedValue = lnew.CodProfissional;
}
else
{
MessageBox.Show("Pedido não cadastrado"}
}

but when it executes the line :

cbbProf.SelectedValue = lnew.CodProfissional;

the selectedvalue is set to null.

My lnew.CodProfissional isn't null, it always have integer values.

Why is this happenning??
 
I

Ian McCaul

Ricardo Luceac said:
Hi all...

I have the following code:

protected override void OnLoad(EventArgs e)
{
_presenter.OnViewReady();
base.OnLoad(e);
lProfs=_presenter.getProfs();
cbbProf.DataSource = lProfs;
cbbProf.ValueMember = "cpf";
cbbProf.DisplayMember="nome";
}

So when the view loads it populates my combobox.
Then when I select a order id and click load, executes the following
method:

private void btnCarrega_Click(object sender, EventArgs e)
{
int ped = Convert.ToInt32(txtPedido.Text);
if (_presenter.existePedido(ped))
{
lnew = _presenter.getLaudo(ped);
btnGrava.Enabled = true;
cbbProf.Enabled = true;
rtbLaudo.Enabled = true;
rtbLaudo.Rtf= lnew.Texto;
cbbProf.SelectedValue = lnew.CodProfissional;
}
else
{
MessageBox.Show("Pedido nC#o cadastrado"}
}

but when it executes the line :

cbbProf.SelectedValue = lnew.CodProfissional;

the selectedvalue is set to null.

My lnew.CodProfissional isn't null, it always have integer values.

Why is this happenning??

try wrapping the databinding within the OnLoad within a
if(!Page.IsPostBack)
{
....
}
 
A

Aneesh Pulukkul [http://dotnet-revolutions.blogspo

Hi all...

I have the following code:

  protected override void OnLoad(EventArgs e)
        {
            _presenter.OnViewReady();
            base.OnLoad(e);
            lProfs=_presenter.getProfs();
            cbbProf.DataSource = lProfs;
            cbbProf.ValueMember = "cpf";
            cbbProf.DisplayMember="nome";
        }

So when the view loads it populates my combobox.
Then when I select a order id and click load, executes the following
method:

private void btnCarrega_Click(object sender, EventArgs e)
{
int ped = Convert.ToInt32(txtPedido.Text);
if (_presenter.existePedido(ped))
{                
lnew = _presenter.getLaudo(ped);
btnGrava.Enabled = true;
cbbProf.Enabled = true;
rtbLaudo.Enabled = true;
rtbLaudo.Rtf= lnew.Texto;          
cbbProf.SelectedValue = lnew.CodProfissional;              }

else
{
MessageBox.Show("Pedido não cadastrado"}

}

but when it executes the line :

cbbProf.SelectedValue = lnew.CodProfissional;

the selectedvalue is set to null.

My lnew.CodProfissional isn't null, it always have integer values.

Why is this happenning??

*** Sent via Developersdexhttp://www.developersdex.com***

It seems that binding is reset during postback. THe binding has to be
done one time. Please check IsPostBack property.
 
Top