8 Replies - 648 Views - Last Post: 08 March 2013 - 08:39 AM Rate Topic: -----

#1 Adqusit  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 143
  • Joined: 02-March 13

How to refresh my combobox

Posted 02 March 2013 - 03:23 AM

Hi. This is my first post to this forum. I've read the rules, written before asking the question in multicolor fashion. some were not picked by my mind but if any mistake then please guide me.


I've a form on which i have a combobbox, in which at the form load even and submit button click event, the items are loaded from the table right. its also enabled with AutoComplete option. So, when i insert the new entry in combobox, so it does not appear, until i close the form and re-open it.
This is my code
 Dim insProd As String = "insert into ProdInfo (Prod_Name, Prod_Pri, Prod_Desc, Prod_Made) values (@Prod_Name, @Prod_Pri, @Prod_Desc, @Prod_Made)"
        Dim cmdSql As New SqlCommand(insProd, cnSql)
        cmdSql.CommandType = CommandType.Text
        daSql.InsertCommand = cmdSql

        With cmdSql

            .Parameters.Add("@Prod_Name", SqlDbType.VarChar).Value = cmbProdName.Text.Trim
            .Parameters.Add("@Prod_Pri", SqlDbType.Int).Value = txtProdPri.Text.Trim
            .Parameters.Add("@Prod_Desc", SqlDbType.VarChar).Value = txtProdDesc.Text.Trim
            .Parameters.Add("@Prod_Made", SqlDbType.VarChar).Value = txtProdMade.Text.Trim

        End With

        cnSql.Open()
        cmdSql.ExecuteNonQuery()
        cnSql.Close()

        MsgBox("Record Inserted Successfully", MsgBoxStyle.OkOnly, "Product Inserted")
        Clear(Me)
        ClearCombo(Me)
        cmbProdName.Focus()


        Dim selProd As String = "select * from ProdInfo"
        Dim cmdSql1 As New SqlCommand(selProd, cnSql)
        cmdSql1.CommandType = CommandType.Text
        daSql.SelectCommand = cmdSql1

        daSql.Fill(dsSql, "ProdInfo")

        Dim s As Integer
        For s = 0 To dsSql.Tables("ProdInfo").Rows.Count - 1
            cmbProdName.Items.Add(dsSql.Tables("ProdInfo").Rows(s).Item(1))
        Next


Please guide me that why it does not show the value, right after the buton click event.

Is This A Good Question/Topic? 0
  • +

Replies To: How to refresh my combobox

#2 intermi  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 02-March 13

Re: How to refresh my combobox

Posted 02 March 2013 - 08:35 AM

Hello... This is my first reply I just joined to the forum :P

Well, I'd like too see first whats the code you are using for the first time you complete the ComboBox...

And why you put the "1" on "Item(1)"?
cmbProdName.Items.Add(dsSql.Tables("ProdInfo").Rows(s).Item(1))

I've used ComboBox before and I think I always used Item(0)...

And one last thing, since you are selecting everything from your DB with the SQL string, maybe you should clear the ComboBox first... I dont know how "ClearCombo(Me)" works, you should try ComboBox1.Items.Clear() and see what happens...

Sorry for my english
Was This Post Helpful? 0
  • +
  • -

#3 Adqusit  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 143
  • Joined: 02-March 13

Re: How to refresh my combobox

Posted 02 March 2013 - 07:12 PM

View Postintermi, on 02 March 2013 - 08:35 AM, said:

Quote

And why you put the "1" on "Item(1)"?
cmbProdName.Items.Add(dsSql.Tables("ProdInfo").Rows(s).Item(1))
The reason for using "1" in item(1) is that on item "0" I've Prod_ID, and on item "1" I've Prod_Name, which I'm actually loading into my ComboBox.

Quote

I've used ComboBox before and I think I always used Item(0)...
It's used in that time when you are getting the very first column very first value.

Quote

And one last thing, since you are selecting everything from your DB with the SQL string, maybe you should clear the ComboBox first... I dont know how "ClearCombo(Me)" works, you should try ComboBox1.Items.Clear() and see what happens...
I've used the Clear and .Refresh both methods, but neither of them is working.

Was This Post Helpful? 0
  • +
  • -

#4 intermi  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 02-March 13

Re: How to refresh my combobox

Posted 02 March 2013 - 07:36 PM

If you add the new data without using Clear it works?

Do you use the exact same routine when the form is loading and the ComboBox gets populated? If not, paste that code too
Was This Post Helpful? 0
  • +
  • -

#5 Adqusit  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 143
  • Joined: 02-March 13

Re: How to refresh my combobox

Posted 03 March 2013 - 06:05 AM

What is this line meaning please?

Quote

Do you use the exact same routine when the form is loading and the ComboBox gets populated? If not, paste that code too

Was This Post Helpful? 0
  • +
  • -

#6 Adqusit  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 143
  • Joined: 02-March 13

Re: How to refresh my combobox

Posted 07 March 2013 - 09:08 AM

View PostAdqusit, on 03 March 2013 - 06:05 AM, said:

What is this line meaning please?

Quote

Do you use the exact same routine when the form is loading and the ComboBox gets populated? If not, paste that code too


Hi, I have used the
cmbProdName.items.Clear
and it solved my problem. Now the last inserted value is also being displayed in the combobox. Thank you so much Intermi for your participation in my thread.
Was This Post Helpful? 0
  • +
  • -

#7 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1537
  • View blog
  • Posts: 4,938
  • Joined: 25-September 09

Re: How to refresh my combobox

Posted 07 March 2013 - 09:11 AM

after the cmbProduName.Items.Clear are you calling the routine to populate the combobox again?

That would be a necessity.

EDIT:
Sorry, didn't see where you had it resolved :D

This post has been edited by CharlieMay: 07 March 2013 - 09:15 AM

Was This Post Helpful? 0
  • +
  • -

#8 intermi  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 02-March 13

Re: How to refresh my combobox

Posted 07 March 2013 - 09:46 AM

View PostAdqusit, on 07 March 2013 - 09:08 AM, said:

View PostAdqusit, on 03 March 2013 - 06:05 AM, said:

What is this line meaning please?

Quote

Do you use the exact same routine when the form is loading and the ComboBox gets populated? If not, paste that code too


Hi, I have used the
cmbProdName.items.Clear
and it solved my problem. Now the last inserted value is also being displayed in the combobox. Thank you so much Intermi for your participation in my thread.


You are welcome :D
Glad to help
Was This Post Helpful? 0
  • +
  • -

#9 Adqusit  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 143
  • Joined: 02-March 13

Re: How to refresh my combobox

Posted 08 March 2013 - 08:39 AM

View PostCharlieMay, on 07 March 2013 - 09:11 AM, said:

after the cmbProduName.Items.Clear are you calling the routine to populate the combobox again?

That would be a necessity.

EDIT:
Sorry, didn't see where you had it resolved :D/>


@ Charlie
Yes that would be necessary, without that its not possible to work. I called the select query and did the same thing which I have done at the end of submit button, shown in my first post i.e. Using the select query, putting data in DataSet and then using for loop to put the data from DatasSet into combobox. Thats it.

Once again thank you very much for assisting me to solve the problem. :) :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1