I would need to populate fields of a form based on the values taken from a selected row in a QTableView displayed on another form. The code works fine for text fields but I'm having problem when I have to set the value of a double spinbox: below is the statement which throw an exception.
The field dSB_costi has been defined on the form with a double spinbox widget. The issue is the field 'self.model.data(self.model.index(row, 4)' taken from the selected row of the QTableView present in the first form (form1) is passed as string.
Additionally the fields taken from the QTableView contains 42,00 as I need use comma as decimal separator.
I tried to use float() to convert the value before the setValue statement but I get the error 'ValueError: could not convert string to float: '42,00'
Thanks for any guidance you might provide
self.w.dSB_costi.setValue(self.model.data(self.model.index(row, 4)))
Related
I have an MS ACCESS Combo Box and I wish to change the value of one of the columns in a particular row. I get error "object required" when I run this line:
Me.ComboName.Column(12, intUseRow) = myVar
(If I am unable to use the above syntax then you should also know that the row I am trying to change is always going to be the "current" visible row so there may be another way of solving the problem due to this fact).
Thanks!
If you have a recordset that is bound to a Table/Query, you will need to change the underlying data then requery the combobox to see changes.
If you load it manually (like in the form load event) and have the comboBox Row Source Type to "Value List" - you should be able to update it like this:
Copy all the data from the selected row into variables.
Combobox.RemoveItem (selected index)
change the required variable to the new value.
construct the semicolon separated string for the value list entry
combobox.AddItem new-string.
a bit messy, but it works correctly!
I made a simple query to return 1 field. One of the fields is the user's input.
Item (input)
Description (return value)
I now want to use the returned value in a simple textbox on the report, but it's giving me a scope error. Makes sense, but how do I tell the textbox which dataset to look in (there are multiple datasets)?
If you right mouse click on the text box you can create a placeholder.
You can then specify the value of this placeholder to be the required value from the dataset.
I am having some trouble with a sorting an unbound DataGridView. I am filling a DataTable from a StreamReader, and then manually transferring the items from the DataTable to the DataGridView. The AllowUserToAddRows property is set to true on the DataGridView.
This populates the DataGridView, without any trouble. I can sort the columns by clicking on the column headers without any issue. If I add a value to the first column in a new row, and then try to sort the column, I get an error message that shows: "Object must be of type String."
I have tried different ways of converting all of the cells in the column to the same datatype, but I cannot get around this issue. Am I missing something here?
In the form load event, I have the following code:
dgvStartingGrid.Columns(0).ValueType = GetType(Integer)
I also am making sure that the values from the StreamReader are Integer types before entering them in the DataGridView:
If IsNumeric(strColumnValue) Then
dtbFillGrid.Rows(intCurrentRow).Item("Starting Position") = strColumnValue
End If
I have also tried:
dtbFillGrid.Rows(intCurrentRow).Item("Starting Position") = CInt(strColumnValue)
What could cause this issue? I have verified that all of the cells in the column are of the same datatype, but it still gives me an error, and I am sure that it is this column that is the problem.
The other columns are of string type, and I do not have any issue sorting them by their column headers, unless I click the first column, and then the exception is thrown.
Right, after some testing I found this out.
Even though you have set your DataGridView column to be Integer it doesn't mean that it will be filled with Integers. Unless you alter the datatype of the DataTable the DataGridView is actually filled with strings. The sorting function on a DataGridView is not based on column type, it is based on the first value it finds. And since you that value is a string, you get an error when it reaches your typed value (which is an Integer).
So here is what you have to do.
dtbFillGrid.Columns.Item(0).DataType = GetType(Integer)
Where 0 is the column containing Integer.
Is there a way to automatically add a new line or something when a column in my ultraGrid is full? Sometimes when i load some text into a column in my ultragrid it has a longer value length than the available column field, as a result some text stays hidden. So i want when this happens to show the rest of the text in another line. Is this possible in vb.net for ultrawingrid?
You could set the CellMultiLine property as in the example below. (supposing you have one band and the column with the long text is the second one)
UltraGrid1.DisplayLayout.Bands(0).Columns(1).CellMultiLine = DefaultableBoolean.True
UltraGrid1.DisplayLayout.Bands(0).Columns(1).VertScrollBar = True
UltraGrid1.DisplayLayout.Override.DefaultRowHeight = 100
The next two lines are optional, but they serve the purpose to show immediately the column with a different height and with a vertical scrollbar
I have a gridview that is bound to a datasource (Windows Forms, VB.NET). One of columns is a property of type boolean, and I want to show "yes/no" in the column instead of 0/1 or "true/false". Is this possible? Can you edit displays of columns that are bound?
I have encountered the same problem, unfortunately I didn't find an elegant solution.
Three workarounds are proposed:
Add another property to the data source's class, which returns your string representation of the boolean property. Hide the column showing the boolean value, display the column showing the string value.
Add an unbound string column, populate that column with the appropriate value for each row, and hide the boolean bound column.
Create a wrapper class for your data class, which exposes the properties as you'd like them to be shown in the datagrid.