Grids get empty when I click on some other tab - vb.net

I have a question, I have a combo box, which when changed fills the data grid. Now Wen I change the Tab and come back to same tab again(one containing the combo box)..the value of combo box remains there, however the grid gets empty. I need this data to be maintained till the user selects another value from drop down.How can this be done???
Any suggestions would be appreciated.

Some of the possible reasons :
There is a MyDataGrid.clear somewhere
The DataSource used to fill the grid is somewhere cleared.
If you use a DataSet, your DataTable is somewhere truncated.
If you use a BindingSource as your DataSource, maybe somewhere else you're using the same BindingSource, which empties the grid.
I would recommend you to put a braekpoint on your Combobox change value event to see if it's not called with a wrong value somewhere else.
And I would add a spy to check your DataGrid (the number of lines for example) to precisely know where it happens by executing my code step by step.
Hope this helps !

Related

VB.Net ComboBox (as Dropdown) not translating text to DisplayMember with Databinding

I inherited a fairly large project at work that is undocumented and written in VB (originally started pre .NET, ended around .NET 2). I'm in the process of updating / refreshing a lot of the code, but have run into an annoying issue that I haven't found the solution for yet. This system utilizes a UI, a Web Service, and a SQL DB.
Problem: I have a Databound Combobox (originally set to DropDownList - I'm changing it to DropDown, which is what started this mess - going back isn't an option) that is tied to a DataSet that comes from a Web Service. When a user types in the item they want manually, the data from the text field doesn't seem to associate itself with the DisplayMember, which forces the WS/SQL query to fail (it is sent a blank value when it's expecting a ValueMember). If the user types in a partial selection and then chooses the value they want from the DisplayMember list using the arrow keys or tab, the query goes off without a problem.
My Question: How do I get the text field to translate to the DisplayMember which will then properly tie itself to the ValueMember which will then allow the query to execute correctly? Sorry for making this sound complicated or convoluted; I'm sure the answer is easy and I'm just glazing over it.
The relevant bit of code is:
With cmbDID
If dtsLU.Tables.Contains(reqTable) = True Then
.DataSource = dtsLU.Tables(reqTable)
.DisplayMember = "zip"
.ValueMember = "gridID"
End If
End With
cmbDID.DataBindings.Clear()
cmbDID.DataBindings.Add("SelectedValue", dtsData, strDT & ".gridID")
I've tried changing "SelectedValue" to "Text", which almost works - but it directly translates to gridID and skips zip which ends up with an incorrect Web Service response since the zip and gridID field values are not synced (zip (DisplayMember) may be 5123 while gridID (ValueMember) may be 6047). I've tried changing "SelectedValue" to "SelectedIndex", and that got me no where.
Any help is greatly appreciated.
EDIT
To add some clarification to the process, the below pseudo code / description is roughly what happens. I could post the whole module, but I feel that would just muddy the whole question even more.
Private Sub A
FormAlpha is created with 1 ComboBox in the form of a DropDown
This DropDown is populated with a DataSet
DataBinding with a blank DataSet is added to the control to keep track of the users input
End Sub
lblSubmit_Click event is triggered on FormAlpha by the user after they have populated the DropDown with their data. lblSubmit_Click calls Private Sub Submit
Private Sub Submit
BindingContext(DropDown DataSet, tableName).EndCurrentEdit() is called
DataSet.HasChanges() is processed
If changes are present, changes are processed
HERE lies the problem
If the user has manually typed in the DropDown field, but not hit an arrow key or tab, then the DataSet registers a change, but returns a null value in all fields - it knows something was entered, but that data apparently didn't pass through the DataSet for the ComboBox (ListItems or SelectedIndex didn't change / fire I'm guessing). If the user selects the item with the arrow keys, the DataSet has the proper input (I'm assuming the Data was validated by the control at this point).
If the processed data is good, a value is entered into the database
If the processed data is bad (empty), an error is returned
End Sub
If the above can't be solved with what I've provided, but someone still knows a better way to handle this type of situation, I'm all ears. Rewriting the module isn't ideal, but fixing this problem is a necessity.
Alright, while this fix may not be ideal, it is a fix none the less.
The bare bones problem was that the text value of the DropDown wasn't causing the data to actually affect the SelectedIndex / SelectedValue of the control unless you interacted with it using the arrow keys or a mouse click. So, while the DropDown would read "1234", in reality the control saw "".
The fix I have in place for this is simply calling comboBox.text = comboBox.text whenever the user hits the submit button.

Selenium wait until combobox contents change

I want to wait until a combobox contents change before getting the contents of that box. I don't think an implicit wait will work here as the element already exists on the page.
I'm not searching for a particular value in this combobox. I have another combobox that is populated by values and depending on what is chosen from this combobox affects the one I'm trying to wait for. There is a lag populating due to access to a database.
Sometimes this combobox may not change it's contents also.
Any suggestions appreciated
Thanks
First and simple idea is to create loop which will verify value in your comboBox until it will not changed to another one, then return back. If time of waiting is too long, then throw exception or smth like this.

Show Data Grid View specified cell value in Textbox

I am a student programmer who is learning VB. I am trying to make a telephone book type project in VB (Windows Forms). In my project I am using an unbound Data Grid View control. Below the Data Grid View, I have some textboxes which will display the values of the selected row. On the form load event, my program accesses a file and populates the Data Grid View control with values from the file. This works perfectly, but the problem I get is when I use the code:
txtLast.Text = dgvMain.Rows.Item(0).Cells(0).Value
to populate the textbox called txtLast with the value at the specified cell, the textbox doesn't display the value. The program doesn't crash or hang, it simply won't display the value and when I try to edit the textbox, it acts as if the textbox is empty. I have tried using
txtLast.Text = dgvMain.Rows.Item(0).Cells(0).Value.ToString()
as well as trying to refresh my Data Grid View control and the textbox. Nothing has worked so far. When I use a breakpoint to see whether that line of code is executed, the autos window shows me that the line of code is executed and that it sees the value of the specified cell as "Smith". However, when I press F11 to step into the next line, the textbox.text property remains as "" instead of changing to "Smith".
Note: when I manually specify the text through the code (i.e. txtLast.Text = "Test") it will show that text. Also, this problem is not with just one textbox, it is with every textbox that I use (I have 5 textboxes showing various values from the specified row). The weird thing is that out of the 5 textboxes, one of them, the masked textbox which shows the phone number works perfectly with the same line of code. (note it is not a problem only affecting regular textboxes as I have tried using both regular textboxes and masked textboxes, both produce the same problem except for the phone textbox).
Also, I would prefer to keep the Data grid view unbound (not connected to a database) and the textboxes unbound (not connected to the data grid view as a data source) because while browsing the internet I have seen people suggesting to bind the textbox or data grid view, however I do not understand how to do so, and I believe that this can be done without binding to a data source.
Any help is appreciated in trying to figure out why the text doesn't change. Let me know if you need any other info or if part of my explanation is unclear.
Thanks!

data from Gridview to textbox

i have a form with datagridview in vb.net that show my data in columns. what i'm trying to accomplish is that after choosing a row and pressing Edit button a new form will open and split the row for the right text boxes to update the data. the datagridview row shows different types of data: name,email,date,etc... any idea? Thanks in advance!
In the EditButton click-handler, you may access the selected row in your datagridview with the MyDataGridView.CurrentRow property.
This object - a DataGridViewRow - has Cells, which you can access individually by index and then get to their values:
...CurrentRow.Cells(n).Value
This then, in turn, you may use to fill the items in your edit form.
After completing your edit form, retrieve the (updated) values and put them back into the CurrentRow.Cells(n).Value
If your datagridview is databound, then you can also work directly with the datastore, through
...CurrentRow.DataBoundItem
The type of this object depends of course on your configuration; it may, for instance, be a DataRow.
This should be enough to get you going.
Final note on your added remark "thanks ...": you're apparently new at this site. I'm not sure why you got "downvotes". It may be because your question is rather elementary ("homework"), or people found your problem description not clear/detailed enough. Please, understand that answers (if any) are provided "unpaid for", and require "voluntary" effort from the contributors. Understandably they prefer that YOU do most of the work/study/trying, before asking someone else "to do your work for you". No offense intended.

When adding a checkbox to a datagridview datatable I get dataerrors

I have a datagridview that I've added a checkbox column to. When I preview my data without the checkbox it works fine. when I run the program and try to load the datatable, I get a data error. I'm not sure what may be causing this. Where can I look to figure out what's causing this error?
Thank you
Doug
Your e.Context returns as Display. If you take a look at MSDN you will see for display it says
A data error occurred when displaying
a cell that was populated by a data
source. This value indicates that the
value from the data source cannot be
displayed by the cell, or a mapping
that translates the value from the
data source to the cell is missing.
In other words the checkbox column in the dgv probably doesn't quite know how to display the information you are giving it. So, chances are you are telling the checkboxes whether they should be true or false incorrectly.
Update: Perhaps, your solution lies with the TrueValue and FalseValue properties of DataGridViewCheckBoxColumn Class. These properties define when a checkbox should be checked or not checked. If you don't have these set, or if you are trying to set your checkboxes to something other than either of the two values in these properties, you would have problems.