hi all
im writing some software at the moment, i have a mysql database backing it all and i have a page called "edit items". its basically a datagrid which displays all the rows from the sql database in the products table.
now i identified a problem which is that if i leave the "category" area just a text box the user will be able to insert any number of different spellings and mis-spellings of the one word. SO to combat this i decided to change the text box style (basic default datagrid) to a drop down box which will load all the available category types (which the user defines earlier in the program set up)
but....when i return the string from the database with all the items....the combo box dies. and i've no idea for to get the combo box to show the correct text for that item.
the working logical order is this:
thats how it should work....but it comes up with...
so im kind of stuck, ive tried every possible combination of "combobox.text, .items .selected .display " that i could think of or looked like it might work.
below is my load items into the combo box code and then the load items code.
thanks
'this is the code that inserts the available category's into the combo box
'combo box design name is 'cat'
'this is the load items code, that populates the datagrid
'string 3 of the myreader.getstring is / should be the combo box column
hope someone can help
thanks muchly
mrlizter
im writing some software at the moment, i have a mysql database backing it all and i have a page called "edit items". its basically a datagrid which displays all the rows from the sql database in the products table.
now i identified a problem which is that if i leave the "category" area just a text box the user will be able to insert any number of different spellings and mis-spellings of the one word. SO to combat this i decided to change the text box style (basic default datagrid) to a drop down box which will load all the available category types (which the user defines earlier in the program set up)
but....when i return the string from the database with all the items....the combo box dies. and i've no idea for to get the combo box to show the correct text for that item.
the working logical order is this:
- load itemedit
- combo box.items = (load category's from database) (*up to here it works - i have rigged a button to do just this and it does load the category list and function properly)
- query database with "select * from products"
- datagrid populate
- add new row's till done (null from database)
- close connection to database.
thats how it should work....but it comes up with...
"The following exception occurred in the datagridview:
System.arguementException: Datagridviewcomboboxcell value is not valid.
To replace this default dialogue handle the dataerror event.:
so im kind of stuck, ive tried every possible combination of "combobox.text, .items .selected .display " that i could think of or looked like it might work.
below is my load items into the combo box code and then the load items code.
thanks
'this is the code that inserts the available category's into the combo box
'combo box design name is 'cat'
VB.NET:
Public Sub load_cat_list()
Dim myConnectionString As String = "Database=james;Data Source=localhost;User Id=root;Password=password"
Dim myConnection As New MySql.Data.MySqlClient.MySqlConnection(myConnectionString)
Dim myInsertQuery As String = "select catname from category"
Dim myCommand As New MySql.Data.MySqlClient.MySqlCommand(myInsertQuery, myConnection)
myConnection.Open()
Dim myReader As MySql.Data.MySqlClient.MySqlDataReader
myReader = myCommand.ExecuteReader()
' Always call Read before accessing data.
While myReader.Read()
Cat.Items.Add(myReader.GetString(0))
End While
' always call Close when done reading.
myReader.Close()
' Close the connection when done with it.
myConnection.Close()
End Sub
'this is the load items code, that populates the datagrid
'string 3 of the myreader.getstring is / should be the combo box column
VB.NET:
Public Sub LoadItems()
DataGridView1.Rows.Clear()
Dim myConnectionString As String = "Database=james;Data Source=localhost;User Id=root;Password=password"
Dim myConnection As New MySql.Data.MySqlClient.MySqlConnection(myConnectionString)
Dim myInsertQuery As String = "select name, price, size, category from product"
Dim myCommand As New MySql.Data.MySqlClient.MySqlCommand(myInsertQuery, myConnection)
myConnection.Open()
Dim myReader As MySql.Data.MySqlClient.MySqlDataReader
myReader = myCommand.ExecuteReader()
' Always call Read before accessing data.
While myReader.Read()
DataGridView1.Rows.Add(New Object() {myReader.GetString(0), myReader.GetString(1), myReader.GetString(2), myReader.GetString(3))}
End While
myReader.Close()
myConnection.Close()
End Sub
hope someone can help
thanks muchly
mrlizter
Last edited by a moderator: