|
www.advancedinstaller.com[^] is, I think, the link for Advanced Installer. Their free version is probably all you need.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
I have a form called frmsettings where the user can make changes to settings in my application. The form has a close button and I can intercept the this.close() method there to make sure they have saved their changes but I do not know how to catch the closing of the form via the X in the upper right hand corner of the form. Pretty much I want to catch the form closing from any method and check to see if they have saved their settings, if not I would like to give them the option to cancel the close. Much thanks
|
|
|
|
|
Have you tried the FormClosing event?
Trinity: Neo... nobody has ever done this before.
Neo: That's why it's going to work.
|
|
|
|
|
There are formclosing and formclosed events
|
|
|
|
|
I tried those events but did not see a way to cancel the event. I can have something happen when the event fires but don't know how to stop the close.
|
|
|
|
|
In the eventhandler of formsclosing event write this:
e.Cancel=true;
Of course it won't work if the program is killed through task manager
|
|
|
|
|
Giorgi Dalakishvili wrote: Of course it won't work if the program is killed through task manager
Actually it will, just use: e.CloseReason .
Trinity: Neo... nobody has ever done this before.
Neo: That's why it's going to work.
|
|
|
|
|
Yes I know that enumeration but you won't be able to cancel application closing if it is killed by task manager
|
|
|
|
|
Very cool, thank you
|
|
|
|
|
hello,
can anyone tell me how I can string.format a double to turn a value of 0.5 into 1/2 or, for example 2.0 into 2/1?
thanks in advance!
/matthias
I love deadlines. I like the whooshing sound they make as they fly by. [Douglas Adams]
|
|
|
|
|
|
Your article is getting smacked pretty hard. You might want to rewrite it so it explains how these things are done instead of just documenting how to use your library.
|
|
|
|
|
You might want to have a look at this:
http://www.codeproject.com/csharp/fractiion.asp
|
|
|
|
|
How can I make the binding between treeviwe and a list contaning of object each object contains a list of athere objects
merwa
|
|
|
|
|
<br />
public class ActiveTable<br />
{<br />
public string omniwinRoot;<br />
public string table;<br />
public string tableKey;<br />
public int tableRecords;<br />
public int tableUniqueRecords;<br />
public int diff;<br />
public Queue<string> doubleKey = new Queue<string>();<br />
public Queue<string> noNversion = new Queue<string>();<br />
<br />
analyzeTable()<br />
{<br />
<br />
}<br />
<br />
}<br />
<br />
<br />
public class form1<br />
{<br />
BindingList<ActiveTable> bindingList1 = new BindingList<ActiveTable>();<br />
dataGridView1.DataSource = bindingList1;<br />
dataGridView1.AutoGenerateColumns = true;<br />
ActiveTable tableToCheck = new AvtiveTable();<br />
<br />
tableTocheck.analyseTable();<br />
if (tableToCeck.doubleKey.Count() > 0)<br />
{<br />
bindingList1.Add(tableToCheck);<br />
<br />
}<br />
<br />
<br />
}<br />
My question is: why doesn't this work.
The DataGridView has a datasource and should be able to generate columns, yes?
Why doesn't my DataGridView create columns and adds rows when items are added to bindinglist?
I've tried lots of different things.
Such as defining the columns myself. With defined columns i see that there are rows added to the DataGridView but the columns remain empty.
Any suggestions?
-- modified at 13:35 Tuesday 29th May, 2007
|
|
|
|
|
sharp source wrote: BindingList listOfDoubleIndexTables = new BindingList();
dataGridView1.DataSource = Bindinglist1;
OK. You define a new BindingList, but then you never use it. You bound the DGV to something called BindingList1.
So, which list does addItemsToBindingList1 add stuff to? What are those items? What does this code look like?
And what does this ActiveTable class have to do with anything?
|
|
|
|
|
Sorry, i only wanted the relevant parts of my code. I messed up and should have reread before posting.
I made some corrections and added a few lines.
Hope it will make more sense.
If you want to, http://users.telenet.be/simonsmeets/source.zip[^] holds the project.
thx 4 your time...
simon
|
|
|
|
|
That still doesn't help. I have no idea what you're trying to bind the DGV to, or what you're trying to display, or why, ...
|
|
|
|
|
Ok, i'll start over.
The goal of the application is to check visual foxpro tables of an application named omniwin for numerous different problems. The important one for this problem is the analysis of the index key's uniqueness.
First the user selects the root of omniwin. After the root is validated this application checks the data tables for double index keys.
All the tables wich have to be checked can be found in a table called tableinfo (tableinfo.dbf) and from that table i take the tablename, index field of table, and location of the file in which it is stored. These variables are stored in an instance of ActiveTable, named tableToAnalyze.
Next the table is analysed by invoking tableToAnalyze.CheckForDoubleKey().
That method checks number of rows (tableToAnalyze.tableRecords) and number of distinct(id) rows (tableToAnalyze.tableUniqueRecords).
If those values do not match the method stores the not distinct keys in a queue (tableToAnalyze.doubleKey)
When the table is checked and tableToAnalyze.doubleKey.count() > 1 the instance tableToAnalyse is added to the BindingList<activetable> listOfDoubleIndexTables.
My intention is to display the BindingList listOfDoubleIndexTables in a DGV on the form. Then I can delete rows before starting a fix method because not all problems should be fixed.
Problem:
I've added a DGV on the form (desinger) and named it: dataGridDoubleKey
I've set the DataSource of the DGV to the appropriate datasource: dataGridDoubleKey.datasource=listOfDoubleIndexTables;
I've set the AutoGenerateColumns property to true.
But the DGV does not create columns and ofcourse does not display any rows.
So i thought, i'll define the rows myself.
i set the the AutoGenerateColumns property to false and defined the colums as such:
//dataGridDoubleKey.Columns.Add("omniwinRoot", "locatie");
//dataGridDoubleKey.Columns[0].Visible = false;
//dataGridDoubleKey.Columns.Add("table", "Table");
//dataGridDoubleKey.Columns.Add("tableKey", "Key");
//dataGridDoubleKey.Columns.Add("tableRecords", "Table records");
//dataGridDoubleKey.Columns[3].Visible = false;
//dataGridDoubleKey.Columns.Add("tableUniqueRecords", "Table Unique Records");
//dataGridDoubleKey.Columns[4].Visible = false;
//dataGridDoubleKey.Columns.Add("diff", "Number of double keys");
//dataGridDoubleKey.Columns.Add("doubleKey", "Queue double keys");
//dataGridDoubleKey.Columns.Add("noNversion", "Queue version id");
//dataGridDoubleKey.Columns[7].Visible = false;
W/o the comment ofcourse. Now i did have columns. And i saw that rows were added to the DGV each time a tableToAnalyze was added tot the bindinglist.
Unfortunately the rows of the DGV were alle emtpy.
My question, what am i doing wrong?
The code:
<br />
using System;<br />
using System.Collections.Generic;<br />
using System.ComponentModel;<br />
using System.Data;<br />
using System.Drawing;<br />
using System.Text;<br />
using System.Windows.Forms;<br />
using System.Windows.Forms.Design;<br />
using System.IO;<br />
using System.Data.OleDb;<br />
<br />
<br />
<br />
namespace nomni<br />
{<br />
<br />
public partial class FormAlgemeen : Form<br />
{<br />
string omniwinRoot;<br />
bool rootIsValid = false;<br />
BindingList<ActiveTable> listOfDoubleIndexTables = new BindingList<ActiveTable>();<br />
BindingList<ActiveTable> listOfNoNversionid = new BindingList<ActiveTable>();<br />
BindingList<string> tableFailedToAnalyze = new BindingList<string>();<br />
<br />
public FormAlgemeen()<br />
{<br />
InitializeComponent();<br />
dataGridDoubleKey = new DataGridView();<br />
dataGridVersionIdProblem = new DataGridView();<br />
<br />
dataGridDoubleKey.DataSource = listOfDoubleIndexTables;<br />
dataGridVersionIdProblem.DataSource = listOfNoNversionid;<br />
<br />
dataGridDoubleKey.AutoGenerateColumns = true;<br />
dataGridVersionIdProblem.AutoGenerateColumns = true;<br />
}<br />
<br />
private void chooseStandardOmniwin(object sender, EventArgs e)<br />
{ <br />
omniwinRoot = "C:\\Program Files\\Omegasoft\\medical\\omniwin\\";<br />
rootIsValid = ValidateOmniWinRoot(omniwinRoot);<br />
if (!rootIsValid)<br />
{<br />
MessageBox.Show("Default directory is not correct.");<br />
}<br />
else<br />
{<br />
this.stripStatusLabel1.Text = "Selected Omniwin Path: " + omniwinRoot;<br />
this.Refresh();<br />
}<br />
<br />
}<br />
<br />
private void browseToOmniwin(object sender, EventArgs e)<br />
{<br />
DialogResult answer;<br />
FolderBrowserDialog browseFolder = new FolderBrowserDialog();<br />
browseFolder.Description = "Select the Omniwin folder";<br />
browseFolder.RootFolder = Environment.SpecialFolder.MyComputer;<br />
answer = browseFolder.ShowDialog();<br />
omniwinRoot = browseFolder.SelectedPath + "\\";<br />
if (omniwinRoot != "" && answer != DialogResult.Cancel)<br />
{<br />
rootIsValid = ValidateOmniWinRoot(omniwinRoot);<br />
if (!rootIsValid)<br />
MessageBox.Show("You chose an incorrect folder path.");<br />
else<br />
{<br />
this.stripStatusLabel1.Text = "Selected Omniwin Path: " + omniwinRoot;<br />
this.Refresh();<br />
}<br />
}<br />
}<br />
<br />
private bool ValidateOmniWinRoot(string rootToValidate)<br />
{ <br />
bool tableInfoBestaat = false;<br />
bool dataTabellen = true;<br />
bool dataTabellenTussen = false;<br />
string tabelDir = "",tabelNaam = "";<br />
string connectionString;<br />
string sqlQuery = "SELECT ctableid, flocation, cdescr, caliasname FROM tableinfo WHERE (NOT (flocation = '')AND NOT (ctablename = ''))";<br />
tableInfoBestaat = File.Exists(rootToValidate + "tableinfo.dbf");<br />
<br />
if (tableInfoBestaat)<br />
{<br />
connectionString = "Provider=VFPOLEDB.1;" + "Data Source=" + rootToValidate + "tableinfo.dbf";<br />
using (OleDbConnection ConnTableInfo = new OleDbConnection(connectionString))<br />
{<br />
try<br />
{<br />
ConnTableInfo.Open();<br />
OleDbCommand command = new OleDbCommand(sqlQuery);<br />
command.Connection = ConnTableInfo;<br />
OleDbDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection);<br />
while (reader.Read())<br />
{<br />
tabelDir = reader.GetString(1).Trim();<br />
tabelNaam = reader.GetString(3).Trim();<br />
dataTabellenTussen = File.Exists(rootToValidate + tabelDir + "\\" + tabelNaam + ".dbf");<br />
if (dataTabellenTussen == false)<br />
{<br />
dataTabellen = false;<br />
logBox.AppendText(tabelNaam + " not found!" + Environment.NewLine);<br />
}<br />
<br />
}<br />
ConnTableInfo.Close();<br />
}<br />
catch (Exception ex)<br />
{<br />
MessageBox.Show(ex.Message + Environment.NewLine + "While opening tableinfo table an error occured." + Environment.NewLine + "Make sure OmniWin is not running.");<br />
}<br />
<br />
}
<br />
}<br />
else<br />
{<br />
return false;<br />
}<br />
if (dataTabellen)<br />
{<br />
logBox.AppendText("All needed Omniwin tables are found." + Environment.NewLine);<br />
if (File.Exists(rootToValidate + "1816.txt"))<br />
{<br />
logBox.AppendText("Version file: 1816.txt" + Environment.NewLine);<br />
}<br />
else<br />
{<br />
logBox.AppendText("Versie bestand is niet aanwezig. \r\n");<br />
}<br />
toolsToolStripMenuItem.Enabled = true;<br />
return true;<br />
}<br />
else<br />
{<br />
toolsToolStripMenuItem.Enabled = false;<br />
return false;<br />
}<br />
}<br />
<br />
<br />
<br />
private void analysisIds(object sender, EventArgs e)<br />
{ <br />
<br />
string sqlQueryTableInfo ="SELECT ctableid, flocation, ctablename, caliasname, cidfield, cidindex, cdatabase FROM tableinfo WHERE (cdatabase = 'dpatient') AND (flocation = 'data') AND (cidfield <> '') ORDER BY caliasname";<br />
string connectionStringTableInfo = "Provider=VFPOLEDB.1;" + "Data Source=" + omniwinRoot + "\\tableinfo.dbf";<br />
<br />
OleDbCommand commandTableInfo = new OleDbCommand(sqlQueryTableInfo);<br />
ActiveTable tableToAnalyze = new ActiveTable();<br />
listOfDoubleIndexTables = new BindingList<ActiveTable>();<br />
<br />
using (OleDbConnection ConnTableInfo = new OleDbConnection(connectionStringTableInfo))<br />
{<br />
try<br />
{<br />
ConnTableInfo.Open();<br />
commandTableInfo.Connection = ConnTableInfo;<br />
OleDbDataReader readerTableInfo = commandTableInfo.ExecuteReader(CommandBehavior.CloseConnection);<br />
while (readerTableInfo.Read())<br />
{<br />
tableToAnalyze = new ActiveTable();<br />
tableToAnalyze.omniwinRoot = omniwinRoot;<br />
tableToAnalyze.table = readerTableInfo.GetString(3).Trim();<br />
tableToAnalyze.tableKey = readerTableInfo.GetString(4).Trim();<br />
tableToAnalyze.CheckForDoubleKey();<br />
tableToAnalyze.diff = tableToAnalyze.tableRecords - tableToAnalyze.tableUniqueRecords;<br />
<br />
if (tableToAnalyze.diff > 0)<br />
{<br />
try<br />
{<br />
listOfDoubleIndexTables.Add(tableToAnalyze);<br />
listOfDoubleIndexTables.ResetBindings();<br />
<br />
}<br />
catch (Exception dataGridErrorDoubleKey)<br />
{<br />
logBox.AppendText("Error adding table to list / datagrid: " + Environment.NewLine + dataGridErrorDoubleKey);<br />
<br />
}<br />
}<br />
<br />
}<br />
ConnTableInfo.Close();<br />
<br />
}<br />
catch (Exception ex)<br />
{<br />
MessageBox.Show(ex.Message + Environment.NewLine + "While opening tableinfo table an error occured." + Environment.NewLine + "Make sure OmniWin is not running.");<br />
}<br />
<br />
}
<br />
logBox.AppendText("***********************************" + Environment.NewLine + "Numbers of tables witch double index key(s) to repair: " + listOfDoubleIndexTables.Count + Environment.NewLine);<br />
foreach (ActiveTable tableToAnalyzeInList in listOfDoubleIndexTables )<br />
{<br />
logBox.AppendText(tableToAnalyzeInList.table + " has " + tableToAnalyzeInList.diff + " double key(s)." + Environment.NewLine);<br />
}<br />
sqlQueryTableInfo = "SELECT ctableid, flocation, ctablename, caliasname, cidfield, cidindex, cdatabase FROM tableinfo WHERE (cdatabase = 'dpatient') AND (flocation = 'data') AND (cidfield <> '') AND (mstructure LIKE '%NVERSIONID%') ORDER BY caliasname";<br />
using (OleDbConnection ConnTableInfo = new OleDbConnection(connectionStringTableInfo))<br />
{<br />
try<br />
{<br />
ConnTableInfo.Open();<br />
commandTableInfo.Connection = ConnTableInfo;<br />
OleDbDataReader readerTableInfo = commandTableInfo.ExecuteReader(CommandBehavior.CloseConnection);<br />
while (readerTableInfo.Read())<br />
{<br />
tableToAnalyze = new ActiveTable();<br />
tableToAnalyze.omniwinRoot = omniwinRoot;<br />
tableToAnalyze.table = readerTableInfo.GetString(3).Trim();<br />
tableToAnalyze.tableKey = readerTableInfo.GetString(4).Trim();<br />
tableToAnalyze.CheckNversionid();<br />
if (tableToAnalyze.noNversion.Count > 0)<br />
{<br />
try<br />
{<br />
listOfNoNversionid.Add(tableToAnalyze);<br />
listOfDoubleIndexTables.ResetBindings();<br />
<br />
}<br />
catch (Exception dataGridErrorVersionid)<br />
{<br />
logBox.AppendText("datagriderror bij version id:" + Environment.NewLine + dataGridErrorVersionid.Message);<br />
}<br />
}<br />
<br />
}<br />
ConnTableInfo.Close();<br />
<br />
}<br />
catch (Exception ex)<br />
{<br />
MessageBox.Show(ex.Message + Environment.NewLine + "While opening tableinfo table an error occured." + Environment.NewLine + "Make sure OmniWin is not running.");<br />
<br />
}<br />
}
<br />
logBox.AppendText("***********************************" + Environment.NewLine + "Numbers of tables with versionid problems to repair: " + listOfNoNversionid.Count + Environment.NewLine);<br />
foreach (ActiveTable tableToAnalyzeInList in listOfNoNversionid)<br />
{<br />
logBox.AppendText(tableToAnalyzeInList.table + " has nversionid problem(s)." + Environment.NewLine);<br />
}<br />
<br />
}<br />
<br />
}<br />
<br />
public class ActiveTable<br />
{<br />
public string omniwinRoot;<br />
public string table;<br />
public string tableKey;<br />
public int tableRecords;<br />
public int tableUniqueRecords;<br />
public int diff;<br />
public Queue<string> doubleKey = new Queue<string>();<br />
public Queue<string> noNversion = new Queue<string>();<br />
public void CheckForDoubleKey()
{<br />
string connectionStringDpatient = "Provider=VFPOLEDB.1;" + "Data Source=" + omniwinRoot + "\\data\\" + table + ".dbf";<br />
string queryNumberRows = "SELECT " + tableKey + " FROM " + table + " WHERE (nversionid = 0) AND (ldeleted = 0) " + "ORDER BY " + tableKey;<br />
string queryDistinctRows = "SELECT DISTINCT " + tableKey + " FROM " + table + " WHERE (nversionid = 0) AND (ldeleted = 0) " + " ORDER BY " + tableKey;<br />
string queryGetNotDistinctId = "SELECT " + tableKey + ",nversionid, ldeleted, count(*) AS count FROM " + table + " GROUP BY " + tableKey + ",nversionid, ldeleted HAVING count > 1 AND nversionid = 0 AND (ldeleted = 0) ";<br />
<br />
try<br />
{<br />
OleDbConnection ConnDpatient = new OleDbConnection(connectionStringDpatient);<br />
OleDbCommand command = new OleDbCommand(queryNumberRows);<br />
command.Connection = ConnDpatient;<br />
ConnDpatient.Open();<br />
<br />
tableRecords = command.ExecuteNonQuery();<br />
command.CommandText = queryDistinctRows;<br />
tableUniqueRecords = command.ExecuteNonQuery();<br />
if (tableRecords - tableUniqueRecords > 0)<br />
{<br />
command.CommandText = queryGetNotDistinctId;<br />
try<br />
{<br />
OleDbDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection);<br />
while (reader.Read())<br />
{<br />
doubleKey.Enqueue(reader.GetString(0).Trim());<br />
}<br />
<br />
}<br />
catch (Exception getDoubleIds)<br />
{<br />
MessageBox.Show(getDoubleIds.Message + Environment.NewLine + "Error while getting double key values.");<br />
}<br />
<br />
}<br />
ConnDpatient.Close();<br />
}<br />
catch (Exception analyzeTableError)<br />
{<br />
if (analyzeTableError.Message != "SQL: Column 'NVERSIONID' is not found." && analyzeTableError.Message != "SQL: Column 'COPNAMEID' is not found.")<br />
{<br />
MessageBox.Show(analyzeTableError.Message + Environment.NewLine + "Error while analyzing table " + table);<br />
}<br />
}<br />
<br />
}<br />
<br />
public void CheckNversionid()<br />
{<br />
string connectionStringDpatient = "Provider=VFPOLEDB.1;" + "Data Source=" + omniwinRoot + "\\data\\" + table + ".dbf";<br />
string queryAll = "SELECT " + tableKey + ", nversionid FROM " + table + " WHERE (ldeleted = 0) ORDER BY " + tableKey + ", nversionid";<br />
OleDbConnection ConnDpatient = new OleDbConnection(connectionStringDpatient);<br />
string previousIndex = "";<br />
<br />
try<br />
{<br />
OleDbCommand command = new OleDbCommand(queryAll);<br />
OleDbCommand commandOnId = new OleDbCommand();<br />
command.Connection = ConnDpatient;<br />
ConnDpatient.Open();<br />
<br />
OleDbDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection);<br />
while (reader.Read())<br />
{<br />
if (reader.GetString(0).Trim() != previousIndex)<br />
{<br />
if (reader.GetValue(1).ToString().Trim() != "0")<br />
{<br />
noNversion.Enqueue(reader.GetString(0).Trim());<br />
<br />
}<br />
}<br />
previousIndex = reader.GetString(0).Trim();<br />
}
<br />
ConnDpatient.Close();<br />
}<br />
catch (Exception analyzeTableError)<br />
{ <br />
if (analyzeTableError.Message != "SQL: Column 'NVERSIONID' is not found." && analyzeTableError.Message != "SQL: Column 'COPNAMEID' is not found.")<br />
{<br />
MessageBox.Show(analyzeTableError.Message + Environment.NewLine + "Error while checking the nversionid's of table: " + table);<br />
<br />
}<br />
}<br />
<br />
}<br />
}<br />
<br />
}
|
|
|
|
|
OK, this was entirely too much code.
If I can follow this pile of spaghetti, you're creating a BindingList to hold something, but you never tell the compiler what. BindingList wants to know what kind of type it's holding, like this:
BindingList listOfDoubleIndexTables = new BindingList<ActiveTable>();
Also, you may want to rewrite the code in the ActiveTable class to expose public data as properties and not public fields.
-- modified at 19:20 Tuesday 29th May, 2007
|
|
|
|
|
that's already in there:
<br />
public partial class FormAlgemeen : Form<br />
{<br />
<br />
BindingList<ActiveTable> listOfDoubleIndexTables = new BindingList<ActiveTable>();<br />
Good point about my modifiers though, i'll rewrite and add some accessor methods later.
|
|
|
|
|
Whooops! Go look at my previous post again.
|
|
|
|
|
wel, defining properties did the trick.
Thanks a lot for your time, and patience
|
|
|
|
|
Hello everyone,
I have a ComboBox with some options to select. I don't wish the user to be able to Edit the options in the ComboBox. Just simply select the options. I have checked the Windows Property of the ComboBox and I cannot find any options to disable the Text Edit of the ComboBox.
I was wondering if anyone can tell me how I can stop the user from editing the options in the ComboBox.
Thank you very much and have a great day.
Khoramdin
|
|
|
|
|
Either use a ListBox or check out the DropDown[^] property of the ComboBox.
|
|
|
|