
Gladimir
Avatar/Signature-
Posts
60 -
Joined
-
Last visited
About Gladimir
- Birthday 12/31/1968
Personal Information
-
Visual Studio .NET Version
Visual Studio .NET Enterprise
-
.NET Preferred Language
C#
Gladimir's Achievements
Newbie (1/14)
0
Reputation
-
Select method works for String, not DateTime.ToString?
Gladimir replied to Gladimir's topic in Database / XML / Reporting
I'm not quite up to speed on all this stuff. Parameters? I use parameters in SQL statements all the time, but I'm not familiar with using them for DataColumn Expressions. Further explanation would be greatly appreciated. -
Select method works for String, not DateTime.ToString?
Gladimir replied to Gladimir's topic in Database / XML / Reporting
I did forget to mention that I was using the pound sign (#) around my date-time as recommended in the DataColumn Expression reference. I will check the regional settings and write a quick stand-alone test case and let you know what I find. I can tell you that the exprDate string would always properly append the lastFileDate string, which would always match the LastModified DateTime value, even in cases where the formatting was different from computer to computer. I tend to think it is not related to formatting because the DataTable.Compute method returns the exact date and time I am going to use to find the file with that exact date and time. Whatever format is returned by the Compute method is the format I use in my Expression. Anyway, I will keep you all posted in this thread. Thanks for the suggestions and the help. I like the 'typeof' tip, very smart. -
I use the DataTable Select method to get find the most recent "LastModified" date in a table of similarly named files. I then use the resulting date and time to get the specific filename and path from the same DataTable. The problem is that this worked fine on my Windows XP machine, but did not work on any of several Windows 2000 computers at the client's location. The Select method would always return 0 (zero) rows even though we were working with the exact same list of files in both locations. As part of some experimentation, I changed the Type of the "LastModified" from "System.DateTime" to "System.String" and everything began working as expected at the client's location. If anyone has any clue as to why I cannot use the "System.DateTime" DataColumn type in the client's Windows 2000 environment when it works perfectly in my Windows XP environment; I would greatly appreciate any input. Here are the relevant code snippets, starting with the DataTable definition: DataTable fileinfo = [color=Blue]new[/color] DataTable("TestFileInfo"); fileinfo.Columns.Add("FileName", Type.GetType("System.String")); fileinfo.Columns.Add("FileSize", Type.GetType("System.UInt64")); [color=Green]/* DEBUG BEGIN: The following line does not work in client environment... fileinfo.Columns.Add("LastModified", Type.GetType("System.DateTime")); */[/color] fileinfo.Columns.Add("LastModified", Type.GetType("System.String")); [color=Green]/* DEBUG END */[/color] fileinfo.Columns.Add("FullPath", Type.GetType("System.String")); And now the logic that performs the lookup using the Select method: [color=Blue]string[/color] exprFile = "FileName LIKE '" + pattern + "*'"; [color=Blue]string[/color] latestFileDate = dtFiles.Compute("MAX(LastModified)", exprFile).ToString(); [color=Blue]string[/color] exprDate = exprFile + " AND LastModified = '" + latestFileDate + "'"; DataRow[] foundRows = dtFiles.Select(exprDate); [color=Blue]string[/color] latestFile = null; [color=Blue]if[/color] (foundRows.Length > 0) latestFile = foundRows[0]["FullPath"].ToString(); [color=Blue]return[/color] latestFile; The above code returns 0 (zero) rows if "LastModified" DataColumn type set to System.DateTime. Any help, suggestions, or even wild guesses would be greatly appreciated.
-
I think you can just use the DataGrid.Select method in the CurrentCellChanged event. For example: [color=Blue]private void[/color] dataGrid1_CurrentCellChanged([color=Blue]object[/color] sender, System.EventArgs e) { [color=Blue]int[/color] rowIndex = dataGrid1.CurrentRowIndex; dataGrid1.Select(rowIndex); }
-
Hi Charlie, As PlausiblyDamp mentioned, it is trivial to loop through all the controls of a form and identify them by type or name. Here is some code: [color=Blue]int[/color] labelCount = 0; [color=Blue]for[/color] ([color=Blue]int[/color] i = 0; i < [color=Blue]this[/color].Controls.Count; i++) [color=Blue]if[/color] ([color=Blue]this[/color].Controls[i].GetType().ToString().EndsWith("Label")) labelCount++; label1.Text = labelCount.ToString(); I used Label1 just to give me a label to count. I hope this helps.
-
I don't think it is as easy as it used to be in VB6. I've never needed a control array in .NET; so I've never done it, but here is an article from Microsoft. Creating Control Arrays in Visual Basic .NET and Visual C# .NET
-
I don't think so. I believe what you are obseving is the cost of the .NET CLR.
-
-
The code is C#, but the objects will be the same for VB. I don't know what the VB equivalent to the using keyword (maybe Inherits) but you'll need these libraries for an Access database. These statements belong at the top of your code file with the other similar statements. using System.Data; using System.Data.OleDb; Now let's define the steps and create a connection object for our MS Access database and create our database connection object. [color=Green]/* Three steps to a database connection: * 1. Create a database connection object for our MS Access database. * 2. Create a data adapter object for our connection object. * 3. Create a command object for our data adapter object.*/ /* Step 1: A database connection object is a .NET connection class and a * connection string. See [url=http://www.connectionstrings.com/]Connection Strings[/url] for more.*/[/color] [color=Blue]string[/color] mdbstr = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=e:\temp\northwind.mdb;"; OleDbConnection mdbConnx = [color=Blue]new[/color] OleDbConnection(); Now, we'll use the connection object in the creation of our data adapter. The data adapter is not always necessary. Depending on what we're trying to do, we could just use a connection object and a command object, but we'll be using the CommandBuilder in this example, which requires an adapter. [color=Green]/* Step 2: A typical data adapter is a .NET data adapter, an SQL statement, * and an instance of a .NET database connection object.*/[/color] [color=Blue]string[/color] strSelect = "SELECT * FROM Customers WHERE (Region Is Null)"; OleDbDataAdapter mdbCustomers = [color=Blue]new[/color] OleDbDataAdapter(strSelect, mdbConnx); At this point, we're actually ready to read records from the database table and start using them in our application, but we'll go ahead and define a command object while we're here. The OleDbCommandBuilder object automatically creates the SQL statements necessary to update a single table from a DataSet, through a data adapter. As with anything that is done "automatically", the OleDbCommandBuilder is not infallible, but it is pretty reliable and I have often used it. [color=Green]/* Step 3: create an OleDbCommandBuilder object to automatically generate SQL * statements for single-table updates if you set the SelectCommand property * of the OleDbDataAdapter.*/[/color] OleDbCommandBuilder custCommands = [color=Blue]new[/color] OleDbCommandBuilder(mdbCustomers); Now let's use these objects in our application. First, we will declare and populate a DataSet, a collection of database tables. We will have only one table in our collection. [color=Green]/* Create a dataset and populate it using the data adapter object. */[/color] [color=Blue]string[/color] dsName = "dsNorthwind"; [color=Blue]string[/color] tableName = "Customers"; DataSet ds1 = [color=Blue]new[/color] DataSet(dsName); [color=Blue]try[/color] { mdbCustomers.Fill(ds1, tableName); } [color=Blue]finally[/color] { mdbConnx.Close(); } Now, throw a DataGrid, a ListBox, and a ComboBox on a windows form and bind them to appropriate elements in our dataset. [color=Green]/* Bind the data in our dataset to our data aware controls.*/[/color] DataTable dt = ds1.Tables[tableName]; dataGrid1.DataSource = dt; comboBox1.DataSource = dt; comboBox1.DisplayMember = dt.Columns["CompanyName"].ColumnName; listBox1.DataSource = dt; listBox1.DisplayMember = dt.Columns["ContactName"].ColumnName; The great part about all of this is coming. Select the drop-down from your ComboBox, scroll all the way down and select the last company name. You'll see the contact name automatically selected in your ListBox and the DataGrid will automatically move the selection caret to the record matching that company name! Brilliant! When you're ready to update, simply call the Update method of the data adapter object, just as you used the Fill method. [color=Green]/* This code will not work without an instance of the OleDbCommandBuilder object. */[/color] [color=Blue]try[/color] { mdbCustomers.Update(ds1, tableName); } [color=Blue]finally[/color] { mdbConnx.Close(); } And you're on your way...
-
Unfortunately, I can offer advice as I am only feeling my way around these areas, but you need to use delegates and events. Basically, you will create a custom EventHandler and custom event in your windows process class and use that in your console application. Like I said, I am just feeling my way around these areas myself, but I can provide some links that should get you well on your way. Most of these are C# oreinted. Microsoft: Events and Delegates Code Project: Events and Delegates simplified Google Search: C# Delegates Events Classes Sorry that I could not be more help and provide an actual code example.
-
Actually, that code doesn't even build. So, that answers my question as to it's appropriateness.
-
TableStyles TableStyles was exactly the problem. The more work I do on this custom datagrid, the deeper the water. Now I am beginning to question what code is appropriate in a windows control library and what should remain on the user-interface (Form1). Here is my code to disable the sorting: public class CustomGrid : System.Windows.Forms.DataGrid { private System.ComponentModel.Container components = null; [color=Blue]private[/color] CurrencyManager cm = (CurrencyManager) [color=Blue]this[/color].BindingContext|[color=Blue]this[/color].DataSource|; [color=Blue]private[/color] DataGridTableStyle dgts = [color=Blue]new[/color] DataGridTableStyle(cm); private ArrayList _selectedColumns; public CustomGrid() { InitializeComponent(); [color=Blue]this[/color].dgts.AllowSorting = [color=Blue]false[/color]; _selectedColumns = new ArrayList(); } } This control uses ColumnStyles to paint the selected columns. Therefore, this custom control will always use TableStyles and a CurrencyManager. I want this control to self-contain all the code needed for the core functionality of column-selection. The CustomColumnStyle is actually part of the class in the same namespace, but is not a nested class in the CustomGrid.
-
Disabling DataGrid Sorting & Project Rebuilding... I'm having one last problem and rebuilding doesn't seem to be handling the changes. My custom datagrid allows the user to select columns. However, when the user Left-Clicks the column header, the column is selected as desired, but it is also Sorted; an undesired effect. So, I modified my CustomGrid class project like so: public class CustomGrid : System.Windows.Forms.DataGrid { private System.ComponentModel.Container components = null; private ArrayList _selectedColumns; public CustomGrid() { InitializeComponent(); [color=Blue]this[/color].AllowSorting = [color=Blue]false[/color]; _selectedColumns = new ArrayList(); } } I selected Rebuild from the Build menu in my CustomGrid project, then selected Rebuild from the Build menu of my TestWindowsApplication, but the sorting still occurs. Any help would be greatly appreciated.
-
Thanks! That worked! Regarding your word of warning, after making changes and rebuilding my custom control, do I simply remove the Reference from my Windows Application and re-add the Reference to get the new changes? Thanks again.
-
I have a solution with two projects. The main project is a Windows Forms Application and the second project is a Windows Control Library. The goal is to use the custom datagrid created in the windows Control Library in the Windows Forms Application and have it show up in the Toolbox for that project. In the Windows Control Library project, I have declared my derived DataGrid, created some properties, and overridden the OnMouseDown event. Here is my class declaration: public class CymiGrid : System.Windows.Forms.DataGrid My new CymiGrid builds without error, but I'm unsure of the next step. I have added it to the Windows Application as a Projects Reference, but that doesn't get it in the Toolbox. I haven't used any objects from the Toolbox in my custom Control Library, not even a DataGrid. Is that what I need to do? Any help is greatly appreciated.