Hello,
I'm using MultiColumnComboBox control.
When I change the SelectedIndex, I need to fill a TextBox with description of that Index.
So, first, I'm filling my Control like this:
private void LoadTI()
{
var query = (from ta in ctx.tblTipoIs.Where(s => s.Ativo == true)
select new
{
ta.TipoIncID,
ta.Codigo,
ta.Descricao
}).OrderBy(s => s.Codigo);
CmbTipoI.DataSource = query.ToList();
CmbTipoI.DisplayMember = "Codigo";
CmbTipoI.ValueMember = "TipoIncID";
CmbTipoI.SelectedIndex = -1;
CmbTipoI.Text = "";
}
This is called on Form Load.
Than, I'm using this code that I got from your Helping Documentation:
private void CmbTipoI_SelectedIndexChanged(object sender, EventArgs e)
{
ComboBoxBaseDataBound c = CmbTipoI as ComboBoxBaseDataBound;
if (c.SelectedIndex > 0) // Changed since c.SelectedIndex is starting 0 on Form Load
{
DataRowView drv = c.Items[c.SelectedIndex] as DataRowView; // Here's the error: "Object not set to an instance of an Object --> drv is null
LblTI.Text = query.Descricao;
}
When I throw a breakpoint in this event, the c.SelectedIndex is > 0, but drv is null!
So, I can't change Index and fill LblTI with Descrição of Selected Index.
Any help?
EDIT: The only way I get my LblTI.Text filled is querying like this...
private void CmbTipoI_SelectedIndexChanged(object sender, EventArgs e)
{
ComboBoxBaseDataBound c = CmbTipoI as ComboBoxBaseDataBound;
if (c.SelectedIndex > 0)
{
var query = (from lc in ctx.tblTipoIs.Where(s => s.TipoIncID == c.SelectedIndex)
select lc).Single();
LblTI.Text = query.Descricao;
}
else
{
LblTI.Text = "";
}
}