c# forms (holy crap i'm not ready for this)
-
Thank you guys. I was googling for over an hour last night (phrasing?). I still have a lot to learn.
-
Uranium-235 wrote:
createDB is topmost enabled and won't let the main form be accessible when it's up.
You don't need Topmost, just make it a dialog so it automatically disables the calling form:
CreateDB dbCreator = new CreateDB();
DialogResult rc = dbCreator.ShowDialog();
// check rc for success etc.Here is a really useful C# tutorial: http://www.charlespetzold.com/dotnet/index.html[^].
actually this is throwing me an error. "
Quote:
Cannot implicitly convert type 'void' to 'System.Windows.Forms.DialogResult
public partial class Main : Form { public Main() { InitializeComponent(); } private void Main\_Load(object sender, EventArgs e) { if(!File.Exists(Directory.GetCurrentDirectory() + "\\\\Tracker.db")) { this.Enabled = false; CreateDB dbForm = new CreateDB(); DialogResult res = dbForm.ShowDialog(); //dbform error if (res == DialogResult.Cancel) Application.Exit(); } } }
public partial class CreateDB : Form
{
public event EventHandler CancelPressed;public CreateDB() { InitializeComponent(); } private void Cancel\_Click(object sender, EventArgs e) { if (CancelPressed != null) CancelPressed(this, EventArgs.Empty); } }
-
You will never learn programming from Google or Youtube. Get yourself a decent book that will teach you properly, starting with the basics. Time spent now will pay dividends in the future.
I learned PHP and VB from googling. Actually I learned PHP because a game named Tribes used the zend engine and I picked up a PHP book and realized I knew the syntax better than the book. Did PHP for 10 years and made some pretty impressive stuff. I also did some stuff in VB that was pretty advanced. But I haven't done it in a few years (like, 4?) Once you learn many of the basics of .net, all I have left is translating it into the syntax of c#, which IMO has better structure than VB, and a structure i'm more familiar with (logic and conditions like PHP, some variables like C++, which I took in high school) I don't think I could relearn the VB crap. I'm used to &&, ||, if() foreach loops, all in PHP. One thing I didn't like is you can't do multiple logical comparisons in switch/case, but that it rarely used in PHP
-
actually this is throwing me an error. "
Quote:
Cannot implicitly convert type 'void' to 'System.Windows.Forms.DialogResult
public partial class Main : Form { public Main() { InitializeComponent(); } private void Main\_Load(object sender, EventArgs e) { if(!File.Exists(Directory.GetCurrentDirectory() + "\\\\Tracker.db")) { this.Enabled = false; CreateDB dbForm = new CreateDB(); DialogResult res = dbForm.ShowDialog(); //dbform error if (res == DialogResult.Cancel) Application.Exit(); } } }
public partial class CreateDB : Form
{
public event EventHandler CancelPressed;public CreateDB() { InitializeComponent(); } private void Cancel\_Click(object sender, EventArgs e) { if (CancelPressed != null) CancelPressed(this, EventArgs.Empty); } }
-
Your
CreateDB
form needs to return a validDialogResult
. See Form.ShowDialog Method (System.Windows.Forms) | Microsoft Docs[^].private void Cancel_Click(object sender, EventArgs e)
{
//if (CancelPressed != null)
// CancelPressed(this, EventArgs.Empty);return DialogResult.Cancel; }
I returned a DialogResult now I get Since 'TechTracker.CreateDB.Cancel_Click(object, System.EventArgs)' returns void, a return keyword must not be followed by an object expression and yeah I tried changing void to DialogResult and it gave me an error on the form
-
private void Cancel_Click(object sender, EventArgs e)
{
//if (CancelPressed != null)
// CancelPressed(this, EventArgs.Empty);return DialogResult.Cancel; }
I returned a DialogResult now I get Since 'TechTracker.CreateDB.Cancel_Click(object, System.EventArgs)' returns void, a return keyword must not be followed by an object expression and yeah I tried changing void to DialogResult and it gave me an error on the form
The
Cancel_Click
is a delegate type, so it cannot return a value. It handles an event and then returns to the framework. You need to return your DialogResult from the main method of the form. See Form.ShowDialog Method (System.Windows.Forms) | Microsoft Docs[^]. -
The
Cancel_Click
is a delegate type, so it cannot return a value. It handles an event and then returns to the framework. You need to return your DialogResult from the main method of the form. See Form.ShowDialog Method (System.Windows.Forms) | Microsoft Docs[^].ok I get it, so I didn't even need cancel_click (this is a delegate, right?) at all since the DialogResult was already cancel in the form properties.
-
ok I get it, so I didn't even need cancel_click (this is a delegate, right?) at all since the DialogResult was already cancel in the form properties.
-
It was so simple in VB, accessing other forms properties. The main form, right after it's drawn, I want to check for a .db file and if it dosen't exist, to make visible a form (already defined) to create it the db file. (form already as always-on-top, but not visible). After a ton of internet research, i'm still where I started. Closest I got gave me a threading error, which I've learned to work around in VB, but this, is just confusing (TechTracker.CreateDB.ActiveForm.Visible = true;) I like how much c# is to PHP AFA structure, loops, arrays, strings. But this stuff is confusing me
ok, been working on it, i'd figure i'd just add to this instead of making a new thread. I've been messing with SQLite. What I want is to make a function to run the query, get row data and return it. Of course, rows are of mixed types, Using GetDataTypeName(), but storing these into an array is impossible because arrays can only be one type is there a way to store the row data into an array? I've tried the reader row data itself, but i'm not sure i'm going about it the right way this is the core section i'm trying. I've successfully done the query and got the data inside the function, just returning it is the problem
sqlite\_cmd = sql\_conn.CreateCommand(); sqlite\_cmd.CommandText = sql\_query; sqlite\_datareader = sqlite\_cmd.ExecuteReader(); SQLLiteReader Row\[\]; //store reader data in an array? for(int i = 0; sqlite\_datareader.Read(); i++) { Row\[i\] = sqlite\_datareader; }
and return the row. I tried passing the reader up by reference but that was unsuccessful My error: Bad array declarator: To declare a managed array the rank specifier precedes the variable's identifier. To declare a fixed size buffer field, use the fixed keyword before the field type.
-
ok, been working on it, i'd figure i'd just add to this instead of making a new thread. I've been messing with SQLite. What I want is to make a function to run the query, get row data and return it. Of course, rows are of mixed types, Using GetDataTypeName(), but storing these into an array is impossible because arrays can only be one type is there a way to store the row data into an array? I've tried the reader row data itself, but i'm not sure i'm going about it the right way this is the core section i'm trying. I've successfully done the query and got the data inside the function, just returning it is the problem
sqlite\_cmd = sql\_conn.CreateCommand(); sqlite\_cmd.CommandText = sql\_query; sqlite\_datareader = sqlite\_cmd.ExecuteReader(); SQLLiteReader Row\[\]; //store reader data in an array? for(int i = 0; sqlite\_datareader.Read(); i++) { Row\[i\] = sqlite\_datareader; }
and return the row. I tried passing the reader up by reference but that was unsuccessful My error: Bad array declarator: To declare a managed array the rank specifier precedes the variable's identifier. To declare a fixed size buffer field, use the fixed keyword before the field type.
oh duh I needed to specify 'Array' but now I get
Array SQLLiteReader Row[];
^^^
"; expected"
^
identifier expected -
oh duh I needed to specify 'Array' but now I get
Array SQLLiteReader Row[];
^^^
"; expected"
^
identifier expectedwait a second I used this
DataTable returnTable = new DataTable();
DataColumn dtColumn;
DataRow dataRow;MessageBox.Show(fieldCount.ToString()); for (int i = 0; i <= (fieldCount - 1); i++) { //MessageBox.Show(sqlite\_datareader.GetDataTypeName(i)); switch (sqlite\_datareader.GetDataTypeName(i)) { case "TEXT": dtColumn = new DataColumn(); dtColumn.DataType = typeof(String); dtColumn.ColumnName = sqlite\_datareader.GetName(i); returnTable.Columns.Add(dtColumn); break; case "INTEGER": dtColumn = new DataColumn(); dtColumn.DataType = typeof(Int32); dtColumn.ColumnName = sqlite\_datareader.GetName(i); returnTable.Columns.Add(dtColumn); break; } } for (int j = 0; sqlite\_datareader.Read(); j++) { for (int k = 0; (k <= fieldCount - 1); k++) { MessageBox.Show(sqlite\_datareader.GetDataTypeName(k)); MessageBox.Show(sqlite\_datareader.GetName(k)); switch (sqlite\_datareader.GetDataTypeName(k)) { case "TEXT": dataRow = returnTable.NewRow(); dataRow\[sqlite\_datareader.GetName(k)\] = sqlite\_datareader.GetString(k); returnTable.Rows.Add(dataRow); //returnTable.Rows.Add(sqlite\_datareader.GetString(k)); break; case "INTEGER": dataRow = returnTable.NewRow(); dataRow\[sqlite\_datareader.GetName(k)\] = sqlite\_datareader.GetInt32(k); returnTable.Rows.Add(dataRow); //returnTable.Rows.Add(sqlite\_datareader.GetString(k)); break; } } \*/
to try to load the query into a datatable (unsuccessfully, datatype problems), and you can just use .load()? That was a day well wasted