Create CheckBoxes

G

Guest

Hi, I have a string array as follows

string[] databases = {"C:\Master.mdb", "C:\Toolbox.mdb", "C:\Import.mdb",
"C:\Library.mde", "C:\User.mdb", "C:\ImpData.mdb"};

I need some code that will check that the database file exists, and if it
does, to create a checkbox on a form for that database.

Thanks
 
C

Carlos J. Quintero [.NET MVP]

I need some code that will check that the database file exists

Use System.IO.File.Exists()
to create a checkbox on a form for that database

Use Form.Controls.Add()

--

Carlos J. Quintero

MZ-Tools 4.0: Productivity add-ins for Visual Studio .NET
You can code, design and document much faster.
http://www.mztools.com
 
G

Guest

Thanks for the advice. I now have the following, but I can't seem to set the
checkboxes width and location. The width needs to be 168 and the vertical
location needs to be 40 down from the previuos checkbox?

string[] databases = {"Master.mdb", "Toolbox.mdb", "Import.mdb",
"Library.mde", "User.mdb", "ImpData.mdb"};

for ( int j = 0; j < databases.Length; j++ )
{
if ( File.Exists(dbFolder + databases[j] ))

chk.Name = databases[j].ToString();
chk.Checked = true;
chk.Location = new System.Drawing.Point(j,chk.Location.X);
chk.Location = new System.Drawing.Point(j,chk.Location.Y);
chk.Text = databases[j].ToString();
chk.ThreeState = false;
Controls.Add(chk);
this.Refresh();
 
C

Cor Ligthert

You mean something as this. (The checkboxes are created dynamicly starting
in the left most top and left position)

\\\
string[] databases = {"Master.mdb", "Toolbox.mdb", "Import.mdb",
"Library.mde", "User.mdb", "ImpData.mdb"};
for ( int j = 0; j < databases.Length; j++ )
{
//if ( File.Exists(dbFolder + databases[j] ))
CheckBox chk = new CheckBox();
chk.Name = databases[j].ToString();
chk.Checked = true;
chk.Location = new System.Drawing.Point(0, j * 20);
chk.Text = databases[j].ToString();
chk.ThreeState = false;
Controls.Add(chk);
this.Refresh();
}

I hope this helps?

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top