
flynn
Avatar/Signature-
Posts
59 -
Joined
-
Last visited
Content Type
Profiles
Forums
Blogs
Events
Articles
Resources
Downloads
Gallery
Everything posted by flynn
-
I have an app that is currently getting data from a remote server, via the internet, and putting that data into a DataGridView. The data (a full client list) is being pulled down when the app is started and displayed. This solution has worked but now the customer is getting too many clients to bring down at one shot. The number of clients is starting to cause a significant delay at startup and I'm looking for a new method of getting the data. The customer wants to keep the DataGridView functionality. I'd like to be able to put a textbox on the form so that on each keystroke I could call a stored proc that would return the first 20 clients that matched the current textbox entry. Then, as the customer would press PageDown or DownArrow, I would retrieve the next 20 that matched the textbox entry. Or if the customer pressed PageUp or UpArrow, I would retrieve the previous 20. Does this design sound workable or am I way off in wanting to accomplish this from a remote server? Can anyone point me toward a sample that would be a good starting point? I realize this will be a significant code change in this part of my application. Current code layout: SqlCommand sc = new SqlCommand(SP_SELECT_CLIENTS, conn); sc.CommandType = CommandType.StoredProcedure; SqlDataAdapter da = new SqlDataAdapter(sc); conn.Open(); da.Fill(dsClients, CLIENT_TABLE_NAME); conn.Close(); // bind table to BindingSource and DataGridView m_ClientBindingSource.DataSource = dsClients.Tables[CLIENT_TABLE_NAME]; dgvClient.DataSource = m_ClientBindingSource; Thanks in advance, flynn
-
- data
- datagridview
-
(and 1 more)
Tagged with:
-
I understand that the quote character is an illegal character in a path name. What I'm not understanding is why the GetPath() call returns such a mangled string ("\"C:\\\"") and not just C:\ (or at least C:\\). I have attached 2 print screens for reference. When the exception occurs, I execute the GetPath() method in the Immediate window (shown in the print screen). It shows the mangled string. Screen shot 2 shows the value of the tsPathLabel as I entered it (C:\) in the properties window. So I guess what I don't understand is why the string has all the 'escaping' when all I enter is C:\ . I can do this: tsPathLabel.Text.Replace("\"",""); but is this a valid way to handle the problem?
-
On my form, I have a ToolStrip that contains a ToolStripLabel that has it's 'Text' property set to "C:\". When I run the following code, the "diDirectory.GetFiles()" method throws an "Illegal characters in path." exception. DirectoryInfo diDirectory = new DirectoryInfo(tsPathLabel.Text); FileInfo[] Files = diDirectory.GetFiles(tsFilter.Text); this.SuspendLayout(); foreach (FileInfo File in Files) { ListViewItem lvi = new ListViewItem(new string[] {File.Name, File.Length.ToString() }); listView1.Items.Add(lvi); } this.ResumeLayout(); This is what is displayed when I print the label in the Immediate window: ? tsPathLabel.Text "\"C:\\\"" ? tsPathLabel.Text.ToString() "\"C:\\\"" The text I was expecting is "C:\". Is there a reason that I'm seeing the text above instead of what I was expecting? tia flynn
-
Nevermind, I found them: Leave/Enter.
-
Am I missing the obvious? Does the ListView control not have an event for losing/gaining focus? Could someone point me in the right direction of how to detect when these 2 events happen on a ListView? thanks in advance, flynn
-
When I step into the event handler to display the ".SourceControl", I print the following in the Immediate window: ? this.cmMRUList.SourceControl.Name 'this.cmMRUList.SourceControl' is null
-
I have 2 textboxes (tbxCustomerName, tbxCustomerNumber) that has a custom context menu attached (cmMRUList). The context menu has a sub-menu (MRUMenuItem_Recent) that contains the most-recently-used customer names. Within the click event (OnMRURecentItemClick(object sender, EventArgs e)) of the MRUMenuItem_Recent items, I need to get the text of the "parent" textbox that the context menu was initiated from. I've looked at the "sender" object to try to find the top level control, but to no avail. The "owner" property of the "sender" contains the context menu itself. Is there a way to get the top level control ?
-
Got it to work. Thanks Nate for your reply. A special thank you to MrPaul, this is exactly what I needed. MrPaul, I mis-read your original post and put the "new" in the definition instead of the method call, and of course the compiler was having none of that!
-
When I type "new" to create the code you suggested, "new" doesn't display in the drop-down that is displayed (this is the closest match: "NewsStyleUriParser"). Am I missing something?
-
I am trying to create a generic class that will take a most-recently-used list and create a context menu for it. The code below (in a slightly different version) works perfect, but only if I have the function "BuildMRUSection()" in the CustomerClass. The reason for this is because the "tsmi.Click += " needs to be able to see the "OnMRURecentItemClick" event handler in order to assign it. What I need to be able to do is pass a pointer to the function "OnMRURecentItemClick" into the MRUList_Dynamic class in order to do the assignment within that class. This will make the routine more encapsulated and easier for the caller. public partial class CustomerClass { MRUList_Dynamic mruDynamic = new MRUList_Dynamic(); private void OnMouseDown(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Right) { MRUList_Dynamic mruDynamic = new MRUList_Dynamic(); mruDynamic.BuildMRUSection(ref MRUMenuItem_Recent); <-- need to be able to pass a function pointer here in order to wire up the mru menu items to the event ((TextBox)sender).ContextMenuStrip = cmMRUList; } } // event handler for all mru menu items clicked private void OnMRURecentItemClick(object sender, EventArgs e) { ToolStripMenuItem tsmi = (ToolStripMenuItem)sender; if (tsmi.Equals(MRUMenuItem_Copy)) Clipboard.SetDataObject(tbxCustomerName.SelectedText); else if (tsmi.Equals(MRUMenuItem_Cut)) { Clipboard.SetDataObject(tbxCustomerName.SelectedText); tbxCustomerName.SelectedText = ""; } else if (tsmi.Equals(MRUMenuItem_Paste)) ; else if (tsmi.Equals(MRUMenuItem_Delete)) tbxCustomerName.SelectedText = ""; else { // set the textboxes based on the mru item selected tbxCustomerName.Text = tsmi.Text; tbxCustomerNumber.Text = tsmi.Tag.ToString(); } } } public class MRUList_Dynamic { public const Int16 NUM_ITEMS = 10; const Byte NAME_COLUMN = 0; const Byte ID_COLUMN = 1; // array contains the "most recently used" items static String[,] MRUArray = new String[NUM_ITEMS, 2] { { "", "" }, { "", "" }, { "", "" }, { "", "" }, { "", "" }, { "", "" }, { "", "" }, { "", "" }, { "", "" }, { "", "" } }; // adds the name/PCN pair in the first slot, moving all other items down 1 slot public static void AddName(String PCN, String sName) { for (Int16 x = NUM_ITEMS - 1; x > 0; x--) { MRUArray[x, ID_COLUMN] = MRUArray[x - 1, ID_COLUMN]; MRUArray[x, NAME_COLUMN] = MRUArray[x - 1, NAME_COLUMN]; } MRUArray[0, NAME_COLUMN] = sName; MRUArray[0, ID_COLUMN] = PCN; } // retrieve the Name at a specific slot public static String GetNameAt(Int16 x) { return MRUArray[x, NAME_COLUMN]; } // retrieve the PCN at a specific slot public static String GetPcnAt(Int16 x) { return MRUArray[x, ID_COLUMN]; } // pass in the pop-up menu as a reference; then create the mru items public void BuildMRUSection(ref ToolStripMenuItem MRUMenuItem_Recent) { // if the dropdown menu items aren't cleared out, items might be duplicated over and over MRUMenuItem_Recent.DropDownItems.Clear(); for (Int16 x = 0; x < NUM_ITEMS; x++) { ToolStripMenuItem tsmi = new ToolStripMenuItem(); if (tsmi.Text != "") { tsmi.Size = new System.Drawing.Size(245, 22); tsmi.Visible = true; tsmi.Click += new EventHandler(OnMRURecentItemClick); //<--- need pointer to "OnMRURecentItemClick" function passed into here MRUMenuItem_Recent.DropDownItems.Add(tsmi); } } } } I've also tried to pre-fill (in the calling class) a ToolStripMenuItem's Click method with the address of the function of the event handler, then pass this into "BuildMRUSection()" as a template to create the mru menu items, but that doesn't work either. // code to pass in a pre-filled "template" of the menu item mruDynamic.BuildMRUSection(ref MRUMenuItem_Recent, tsmi_tmp); public void BuildMRUSection(ref ToolStripMenuItem MRUMenuItem_Recent, ToolStripMenuItem item_template)
-
Is it not possible to capture every CONTROL-x keyboard combination, where "x" is any alphabetic character? Using the following code, I can't seem to capture CTRL-J, but CTRL-F works. Protected Overrides Function ProcessCmdKey(ByRef msg As System.Windows.Forms.Message, ByVal keyData As System.Windows.Forms.Keys) As Boolean If (keyData = (Keys.Control Or Keys.J)) Then Console.WriteLine("You pressed CTRL+J") Return (True) End If If (keyData = (Keys.Control Or Keys.F)) Then Console.WriteLine("You pressed CTRL+F") Return (True) End If Return MyBase.ProcessCmdKey(msg, keyData) End Function
-
I am tasked with creating a generic "end-user" query tool. One of the features is the ability to query on any field of any table. I have most of my design done, but I still need the ability to determine if a column is based on a "number" type. The type can any of the "number" types: tinyint, bigint, numeric, decimal, money, etc. Basically any column that can be compared using "<", ">" or "=" operators. Using "exec sp_columns 'customer'", I can get a list of the columns and data types (column "TYPE_NAME"), but I was hoping that there was an easier way to determine what columns I can apply the "<>=" operators. If there isn't then I guess I'm stuck with looping through the column types to determine if the selected column can be used as a "number" type. Typical use would be allowing the end-user to select a column from a list of available columns, then select an operator (<>=), then type a number in a text box to use as the compared value. tia, flynn
-
Thank you Nerseus. This is the part that had me stumped: INNER JOIN sales_rep sr ON sr.rep_id = c.rep_id AND ( (sr.employee_number = c.employee_number) OR ( sr.territory = @sr_territory and sr.branch = c.branch ) )
-
Given this SQL query (which uses the old style "WHERE" clause to do joins): SELECT c.cust_id, c.name, c.address_1, c.address_2, c.address_3, c.city, c.state, c.zipcode, co.first_name, co.last_name , co.fax, sr.rep_name, sr.rep_phone, sr.rep_fax, sr.rep_email FROM customer c, contact co, sales_rep sr, customer_price cp WHERE ( c.static_cust_numb = cp.static_cust_numb ) and ( c.rep_id = sr.rep_id ) and ( cp.sales_code = @cp_sales_code ) AND ( c.employee_number = sr.employee_number or ( sr.territory = @sr_territory and sr.branch = c.branch )) AND ( c.status <> @customer_status ) AND ( c.rep_id = @rep_id ) AND ( co.default_contact = 'Y' AND c.static_cust_numb = co.static_cust_numb ) Can someone translate to use "JOIN" statements instead of using the "WHERE" statement? In particular, I'm not quite sure how to translate this line ( c.employee_number = sr.employee_number or ( sr.territory = @sr_territory and sr.branch = c.branch )) AND Thanks in advance, flynn
-
Is there a way to force the DataGridView's "Edit Columns" dialog box to resize (on open) so that all the properties are visible? Every time I open it, I resize it so I can see *ALL* the properties without having to scroll. tia, flynn
-
Thanks for the tip, MrPaul.
-
I finally figured it out. Duh! I had to add the following code to dynamically create the new columns, then clone the original columns. foreach (DataGridViewColumn dgvCol in dgv1.Columns) { [color="Red"] DataGridViewColumn dgvNewCol = new DataGridViewColumn(); dgvNewCol = (DataGridViewColumn)dgvCol.Clone(); [/color] dgv2.Columns.Add(dgvNewCol); }
-
I have 2 DataGridView controls on my search form. I have manually created the columns for the 1st grid, but now I want to dynamically duplicate those columns in the 2nd grid. Using the code below, I get this error: "Provided column already belongs to the DataGridView control." Control[] ctl = CustomerSearch.Controls.Find("dgvSearch",false); foreach (DataGridViewColumn dgvCol in ((DataGridView)ctl[0]).Columns) { dgvSelected.Columns.Add(dgvCol); } I'm not sure what the error is trying to tell me. The dgvSelected grid has 0 (zero) columns before this code is ran. "CustomerSearch" is a user-control that contains a DataGridView control called "dgvSearch". Any ideas as to why I am getting this error? tia, flynn
-
I have a combobox that is populated with a list of possible values from a database table. Then I bind the combobox so that a specific value shows. All normal stuff, but what I need to be able to do is to allow the user to drop down the combo but DO NOT let them select anything (only view other values). I know this might not be the standard combobox operation, but this is what the customer wants. Any ideas? tia, flynn
-
Finally figured it out: update activity set FullDateTime = colDate + colTime
-
I have 2 columns that I need to combine into 1. Both columns are datetime. colDate has the date and colTime has the time. I would like to create a new column called FullDateTime that would hold the concatenation of these 2 columns. This is what I have so far, but it isn't quite right: Alter Table activity Add FullDateTime datetime; insert into [activity] ([FullDateTime]) values (select (colDate + colTime) from activity) alter table activity drop column colDate alter table activity drop column colTime Can someone point me in the right direction? tia, flynn
-
I am trying to add a new row to a BOUND DataGridView control. The "AllowUserToAddRows" property is set to false (the user must right click the grid, then select "New Row" from a context menu). private void AddNewContactLineToGrid() { // deselect the currently selected row if (dgvContacts.SelectedRows.Count > 0) dgvContacts.SelectedRows[0].Selected = false; // add a new row to the underlying table, which will add a row to the data grid view dsCustomer.Tables["customer"].Rows.Add(dsCustomer.Tables["customer"].NewRow()); // the following line throws an exception dgvContacts.CurrentCell = dgvContacts.Rows[dgvContacts.Rows.Count - 1].Cells[1]; } The "add" portion of the function works, but when I try to change the CurrentCell to the first visible column of the newly added row (I want to go into edit mode as soon as the new row is added), I get this error: System.InvalidOperationException was unhandled. Operation did not succeed because the program cannot commit or quit a cell value change. A Google search on this message (and small subsets of it) returned nothing. Does anyone have any ideas? The stack trace: System.InvalidOperationException was unhandled Message="Operation did not succeed because the program cannot commit or quit a cell value change." Source="System.Windows.Forms" StackTrace: at System.Windows.Forms.DataGridView.set_CurrentCell(DataGridViewCell value) at eMagine.CustomerForm.AddNewContactLineToGrid() in C:\Data\Projects\CustomerForm.cs:line 319 at eMagine.CustomerForm.PopupNew_Clicked(Object sender, EventArgs e) in C:\Data\Projects\CustomerForm.cs:line 304 at System.Windows.Forms.ToolStripItem.RaiseEvent(Object key, EventArgs e) at System.Windows.Forms.ToolStripMenuItem.OnClick(EventArgs e) at System.Windows.Forms.ToolStripItem.HandleClick(EventArgs e) at System.Windows.Forms.ToolStripItem.HandleMouseUp(MouseEventArgs e) at System.Windows.Forms.ToolStripItem.FireEventInteractive(EventArgs e, ToolStripItemEventType met) at System.Windows.Forms.ToolStripItem.FireEvent(EventArgs e, ToolStripItemEventType met) at System.Windows.Forms.ToolStrip.OnMouseUp(MouseEventArgs mea) at System.Windows.Forms.ToolStripDropDown.OnMouseUp(MouseEventArgs mea) at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks) at System.Windows.Forms.Control.WndProc(Message& m) at System.Windows.Forms.ScrollableControl.WndProc(Message& m) at System.Windows.Forms.ToolStrip.WndProc(Message& m) at System.Windows.Forms.ToolStripDropDown.WndProc(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg) at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData) at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context) at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context) at System.Windows.Forms.Application.Run(Form mainForm) at eMagine.Program.Main() in C:\Data\Projects\eMagine Client\eMagine400\eMagine400\Program.cs:line 34 at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args) at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args) at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() at System.Threading.ThreadHelper.ThreadStart_Context(Object state) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ThreadHelper.ThreadStart() tia, flynn
-
I am wanting to change the backcolor of a specific row/cell in a DataGridView control using the following code: private void CustomGridCellFormatting(object sender, DataGridViewCellFormattingEventArgs e) { if (dgSearchResults.Columns[e.ColumnIndex].Name.Equals("column1")) { // Ensure that the value is a string. String stringValue = e.Value as string; if (stringValue == null) return; switch (stringValue) { case "G": e.CellStyle.BackColor = Color.Gold; break; case "S": e.CellStyle.BackColor = Color.Silver; break; case "N": break; } } } This delegate gets called but the backcolor doesn't change. Am I missing something? tia, flynn
-
The ESCAPE key can be trapped on a form by setting the "KeyPreview" property to true, but the user control does not have this property. Does anyone know how to trap a specific key on a user control, no matter what control on that user control has the focus? I need this functionality so that if the user presses the ESCAPE key, I can hide the user control until it is needed later. I'm guessing that a user control is treated exactly the same as a textbox control (or other control) in that there is no KeyPreview for those controls. I suppose I'll have to trap the ESCAPE key on the Form that contains the user control, then act accordingly, correct? tia, flynn
-
That's basically what I did. Thanks again sdlangers for the help (and the link).