Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DBComboBox!!!

Status
Not open for further replies.

cyprus106

Programmer
Apr 30, 2001
654
I've got this database connection and everything works great in it but I needed a drop down box for one of the fields in the table. I used DBComboBox and set the DataSource and DataField properties accordingly and when I connected to the database and dropped down the box it shows the items I want it to show, thanks to this code:

while (!Table1->Eof)
{
ComboBox->Items->Add(Table1->FieldByName("Name")->AsString);
Table1->Next();
}

But when I click to select one of the items, it disappears. I cannot select an item! I tried checking the OnClick and OnChange events but neither even fired up. What's the problem?!? Cyprus
 
Hi there

Can you please tell us where you placed this code,

while (!Table1->Eof)
{
ComboBox->Items->Add(Table1->FieldByName("Name")->AsString);
Table1->Next();
}

Also when you say:
But when I click to select one of the items, it disappears.

What exactely disappears?

Hope to hear from you soon :)

 
ok, I placed that right after I activated the table:
Table1->Active = true;

And What I mean is that when I click to drop the menu down it shows me all of the items in the field I wanted, and I'll click on one of the items and instead of the drop down menu disappearing and the item showing up in the edit box, nothing shows up. I've tried all of the Style properties and changed the read only and ANYTHING that could constitute this behavior but got nothing... Cyprus
 
Hi Cyprus

I'm having trouble duplicating your problem.

Here, I created a totally new project with one form and with only this code

//OnShow event for Form1
void __fastcall TForm1::FormShow(TObject *Sender)
{
Table1->Active=true;

while (!Table1->Eof)
{
DBComboBox1->Items->Add(Table1->FieldByName("Name")->AsString);
Table1->Next();
}

Table1->First();

}
//---------------------------------------------------------------------------

You can copy and paste this text below onto a new Form, lets see if you still get the same results

object DBGrid1: TDBGrid
Left = 16
Top = 80
Width = 489
Height = 185
DataSource = DataSource1
TabOrder = 0
TitleFont.Charset = DEFAULT_CHARSET
TitleFont.Color = clWindowText
TitleFont.Height = -11
TitleFont.Name = 'MS Sans Serif'
TitleFont.Style = []
end
object DBNavigator1: TDBNavigator
Left = 152
Top = 40
Width = 240
Height = 25
DataSource = DataSource1
TabOrder = 1
end
object DBComboBox1: TDBComboBox
Left = 200
Top = 280
Width = 145
Height = 21
DataField = 'Name'
DataSource = DataSource1
ItemHeight = 13
TabOrder = 2
end
object DataSource1: TDataSource
DataSet = Table1
Left = 24
Top = 32
end
object Table1: TTable
DatabaseName = 'BCDEMOS'
TableName = 'country.DB'
Left = 24
Top = 64
end




 
OK, I think I know my problem. I think. I recreated your project and my problem still stood but under my DBComboBox, I think I had an incorrect field. It was showing me my values but when I would click on them they would not show up in the edit box. It originally didn't work again in your program (tho I had to do some tewaknig to get it to even compile) In the process I changed the DBComboBox DataSource to fit my DBase and I think I accidentally put the table name in where DataSource is supposed to contain a field. Why or how it still managedto show me data is beyond me. Maybe it just substituted in the primary key.
Anyways, thanks. I think I've got it figured out. Cyprus
 
Edit1->Text = DBComboBox1->Items->Strings (DBComboBox1->ItemIndex);
or
Edit1->Text = DBComboBox1->Text;

are you using a TEdit or a TDBEdit.

if TDBEdit you should probably post ();

TDBEdit -> field = table1->field1.// property

table1->field1 = DBComboBox1->Text;
table1->Post ();

ps not verbatim.

give us your onclick event It probably would make things clearer.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top