My TextBox lacks discipline and Forms.Focus
-
I am having some difficulty with a DataGrid object in my Forms application and could greatly use some advice/assistance. My DataGrid is receiving constant updates from a server application with changing data. This is reflected by changing the DataTable object that is set as it's DataGrid.DataSource. The problem is, however, that these refreshes seem to steal Focus from other Controls (TextBox, ComboBox) that are needed. At the moment, I have to repeatedly keep trying to hit a button and hope that I can finally land a OnButtonClicked event between refreshes for it to finally register. Now I have another application that is doing a very similar thing, but it does not have this problem. At first I noticed that the other application doesn't have the other buttons on the same Panel, but after trying to put my DataGrid inside it's own Panel, it's own TabPage, and even grouping my Buttons within a GroupBox, the Buttons and TextBox can't seem to keep focus for long enough to do anything. I've set my DataGrid to "TabStop = false" and even "CausesValidation = false", but these also did not help. The DataGrid became my all-seeing all-knowing master of Focus, and I am now it's slave. Here's a visual to help understand the layout and visualize the problem: Take a look![^] If anybody has any advice or help, it would be greatly appreciated! :)
-
I am having some difficulty with a DataGrid object in my Forms application and could greatly use some advice/assistance. My DataGrid is receiving constant updates from a server application with changing data. This is reflected by changing the DataTable object that is set as it's DataGrid.DataSource. The problem is, however, that these refreshes seem to steal Focus from other Controls (TextBox, ComboBox) that are needed. At the moment, I have to repeatedly keep trying to hit a button and hope that I can finally land a OnButtonClicked event between refreshes for it to finally register. Now I have another application that is doing a very similar thing, but it does not have this problem. At first I noticed that the other application doesn't have the other buttons on the same Panel, but after trying to put my DataGrid inside it's own Panel, it's own TabPage, and even grouping my Buttons within a GroupBox, the Buttons and TextBox can't seem to keep focus for long enough to do anything. I've set my DataGrid to "TabStop = false" and even "CausesValidation = false", but these also did not help. The DataGrid became my all-seeing all-knowing master of Focus, and I am now it's slave. Here's a visual to help understand the layout and visualize the problem: Take a look![^] If anybody has any advice or help, it would be greatly appreciated! :)
-
Just try one trick. Before loading data to datagrid disable it and, once data is loaded make it enable.
dataGridView1.Enable=false;
dataGridView1.Datasource=dataTable1;
dataGridView1.Enable=true;HTH
Jinal Desai - LIVE Experience is mother of sage....
Well, I finally discovered the problem. It was a side affect of the DataGrid being updated, and not the update itself. On an update, any changed data is sent to the TextBox and that part of the system was unaware to me. They were losing their focus because all objects were trying to refresh their data and not just the DataGrid. Also, the update to the DataGrid was being done through a DataTable, in which I never did need to refresh the DataSource variable. You simply have to:
// Current Row
DataRow row = _pumpTable.Rows[index];// Edit Pump
row.BeginEdit();// Do Changes Here:
row.EndEdit();
// Accept Changes
row.AcceptChanges();Thank you for your reply!