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.ControlCollection
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.LookUpSql.StartsWith("Select",StringCompari son.CurrentCultureIgnoreCase))
{
classname = "TBR.NET." + ExtractText.GetClassName(ctl.LookUpSql);
obj = (ILookUpObject)Activator.CreateInstance(Type.GetTy pe(classname));
if (obj == null)
throw new ApplicationException("Cannot create object for type " +
classname);
ds = obj.GetLookupData(ExtractText.ParseSQL(ctl.LookUpS ql));
if (ctl.FieldName == "PayFrequency")
Console.WriteLine("");
switch (ctl.ColumnCount)
{
case 2:
cmb.DisplayMember = "Description";
cmb.ValueMember = "ID";
cmb.DataSource = ds.Tables[0];
break;
case 1:
foreach (DataRow dr in ds.Tables[0].Rows)
{
cmb.Items.Add(dr[0]);
}
break;
default:
break;
}
if (ctl.IsRowLookup == true)
{
cmb.ForeColor = TBRSettings.Instance.Settings.FilterFieldForeColor ;
cmb.BackColor = TBRSettings.Instance.Settings.FilterFieldBgColor;
cmb.SelectedIndexChanged += delegate(Object s, EventArgs e)
{
LoadData((int)cmb.SelectedValue);
};
}
}
else
{
string[] words;
List<ComboItemlist = new List<ComboItem>();
words = ctl.LookUpSql.Split(';');
cmb.Items.Clear();
if (ctl.ColumnCount == 1)
{
foreach (string word in words)
{
cmb.Items.Add(word.Replace("\"", ""));
}
}
else if(ctl.ColumnCount == 2)
{
for (int i = 0; i <words.Length; i += 2)
{
list.Add(new ComboItem(Convert.ToInt32(words[i]), words[i+1].Replace("\"",
"")));
}
cmb.DisplayMember = "Description";
cmb.ValueMember = "ID";
cmb.DataSource = list;
}
}
}
cmb.SelectedIndex = -1;
controls.Add(cmb);
}
public void FindByValue(string value, string columnname)
{
int aIndex;
DataRowView drv;
ComboDebug.Instance.list.Add(this.Name + " ---- NumItems: " +
this.Items.Count);
for (aIndex = 0; aIndex < this.Items.Count; aIndex += 1)
{
try
{
drv = (DataRowView)this.Items[aIndex];
if (drv.Row[columnname].ToString() == value)
{
ComboDebug.Instance.list.Add(this.Name + " ---- " + columnname + " ----- " +
value);
this.SelectedIndex = aIndex;
return;
}
}
catch (Exception)
{
if(this.Items[aIndex].ToString() == value)
{
ComboDebug.Instance.list.Add(this.Name + " ---- " + columnname + " ----- " +
value);
this.SelectedIndex = aIndex;
return;
}
}
}
this.SelectedIndex = -1;
return;
}
"AlexS" <sa***********@SPAMrogers.comPLEASEwrote in message
news:eS**************@TK2MSFTNGP03.phx.gbl...
Demonstrating the problem. Bare bones.
"Rotsey" <ma***********@RemoveThis.optusnet.com.auwrote in message
news:ua**************@TK2MSFTNGP06.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.comPLEASEwrote in message
news:%2****************@TK2MSFTNGP03.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.optusnet.com.auwrote in message
news:uZ**************@TK2MSFTNGP06.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