Alex
i have discovered a problem with it.
When I intiialise the combo with a datatable the datatable
has 20 rows in it. The form displays fine as in I see the items
in the combo but when it goes to set the item in the combo
the number of items in the collection is zero. Weird
If this code helps here is 2 methods. First one is
the creation of the combo and the other a method to
set the selected item.
private void CreateComboBox( ControlDef ctl, Control.Control Collection
controls)
{
TBRComboBox cmb = new TBRComboBox();
string classname;
ILookUpObject obj;
DataSet ds;
cmb.Name = ctl.FieldName;
cmb.Top = ctl.Top;
cmb.Left = ctl.Left;
cmb.Width = ctl.Width;
if (ctl.LookUpSql != "NIL")
{
if(ctl.LookUpSq l.StartsWith("S elect",StringCo mparison.Curren tCultureIgnoreC ase))
{
classname = "TBR.NET." + ExtractText.Get ClassName(ctl.L ookUpSql);
obj = (ILookUpObject) Activator.Creat eInstance(Type. GetType(classna me));
if (obj == null)
throw new ApplicationExce ption("Cannot create object for type " +
classname);
ds = obj.GetLookupDa ta(ExtractText. ParseSQL(ctl.Lo okUpSql));
if (ctl.FieldName == "PayFrequen cy")
Console.WriteLi ne("");
switch (ctl.ColumnCoun t)
{
case 2:
cmb.DisplayMemb er = "Descriptio n";
cmb.ValueMember = "ID";
cmb.DataSource = ds.Tables[0];
break;
case 1:
foreach (DataRow dr in ds.Tables[0].Rows)
{
cmb.Items.Add(d r[0]);
}
break;
default:
break;
}
if (ctl.IsRowLooku p == true)
{
cmb.ForeColor = TBRSettings.Ins tance.Settings. FilterFieldFore Color;
cmb.BackColor = TBRSettings.Ins tance.Settings. FilterFieldBgCo lor;
cmb.SelectedInd exChanged += delegate(Object s, EventArgs e)
{
LoadData((int)c mb.SelectedValu e);
};
}
}
else
{
string[] words;
List<ComboIteml ist = new List<ComboItem> ();
words = ctl.LookUpSql.S plit(';');
cmb.Items.Clear ();
if (ctl.ColumnCoun t == 1)
{
foreach (string word in words)
{
cmb.Items.Add(w ord.Replace("\" ", ""));
}
}
else if(ctl.ColumnCo unt == 2)
{
for (int i = 0; i <words.Length ; i += 2)
{
list.Add(new ComboItem(Conve rt.ToInt32(word s[i]), words[i+1].Replace("\"",
"")));
}
cmb.DisplayMemb er = "Descriptio n";
cmb.ValueMember = "ID";
cmb.DataSource = list;
}
}
}
cmb.SelectedInd ex = -1;
controls.Add(cm b);
}
public void FindByValue(str ing value, string columnname)
{
int aIndex;
DataRowView drv;
ComboDebug.Inst ance.list.Add(t his.Name + " ---- NumItems: " +
this.Items.Coun t);
for (aIndex = 0; aIndex < this.Items.Coun t; aIndex += 1)
{
try
{
drv = (DataRowView)th is.Items[aIndex];
if (drv.Row[columnname].ToString() == value)
{
ComboDebug.Inst ance.list.Add(t his.Name + " ---- " + columnname + " ----- " +
value);
this.SelectedIn dex = aIndex;
return;
}
}
catch (Exception)
{
if(this.Items[aIndex].ToString() == value)
{
ComboDebug.Inst ance.list.Add(t his.Name + " ---- " + columnname + " ----- " +
value);
this.SelectedIn dex = aIndex;
return;
}
}
}
this.SelectedIn dex = -1;
return;
}
"AlexS" <sa***********@ SPAMrogers.comP LEASEwrote in message
news:eS******** ******@TK2MSFTN GP03.phx.gbl...
Demonstrating the problem. Bare bones.
"Rotsey" <ma***********@ RemoveThis.optu snet.com.auwrot e in message
news:ua******** ******@TK2MSFTN GP06.phx.gbl...
>The problem seems to be that the tabs that aren't visible aren't
selecting the combo items, because when I click on a tab and then
reselect the filter the combos are fine.???
How much code would you like to see?
"AlexS" <sa***********@ SPAMrogers.comP LEASEwrote in message
news:%2******* *********@TK2MS FTNGP03.phx.gbl ...
>>re: Sometimes it works sometimes they are set at the first item in the
list.
Most probably it's bad logic. Can you post code demonstrating problem?
"Rotsey" <ma***********@ RemoveThis.optu snet.com.auwrot e in message
news:uZ****** ********@TK2MSF TNGP06.phx.gbl. ..
Hi,
I am loading a tab control on a form.
The code loads textboxes and comboboxes and checkboxes, normal
data entry form that loads a table row of data.
I have a combo on the form above the tab control that filters the form
for me.
But I am finding that it is hit or miss whether the comboboxes
have the selected item set from the underlying table when filtering
Sometimes it works sometimes they are set at the first item in the
list.
Textboxes seem fine.
If the tabpage is not visible would this cuase this???
Any ideas??
rotsey