
archer_coal
Avatar/Signature-
Posts
96 -
Joined
-
Last visited
Personal Information
-
Occupation
Web Developer
-
Visual Studio .NET Version
.Net Standard
-
.NET Preferred Language
VB.Net ASP.Net
archer_coal's Achievements
Newbie (1/14)
0
Reputation
-
it works It does work. I had multiple bindings my bad. Thanks a lot for your help Mutant
-
Ok i set the datasource to nothing But somthing still isnt right. Listbox2.Datasource = Nothing Listbox2.Items.Clear() '<-- does nothing now Listbox2.Items.Add("test string")' <-- does not appear in the listbox
-
"Error: Can't modify the Items collection when the DataSource property is set." I need some method of discarding the existing datasource before i can edit the listbox items.
-
I'm having trouble with a databound listbox In the help files for vb.net it says to just bind the listbox again after new data has been Inserted. This produces Duplicates in the listbox. How do i clear the databox before i re-bind it? listbox1.Datasource.Clear() does nothing or so it seems. Simpley put, i want to empty the listbox then rebind it.
-
Listbox update with datasource
archer_coal replied to archer_coal's topic in Database / XML / Reporting
re I also had to add Listbox1.ValueMember = Nothing to the delete Button to get rid of the error. Just in case anyone else was following this thread i thought i should post it. Thanks for your help everyone! It works fine now. Private Sub cmdDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdDelete.Click Dim testmsg As Integer Dim iVar As String iVar = ListBox2.SelectedItem(0) Label1.Text = iVar testmsg = MsgBox("Are you sure you want to remove this reminder?", 1, "Delete Reminder") If testmsg = 1 Then Dim myConnection As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\data\20304aa1.mdb") myConnection.Open() Dim MyCommand As New OleDbCommand("DELETE * FROM reminders where id = " & iVar, myConnection) MyCommand.ExecuteNonQuery() myConnection.Close() MyCommand.Dispose() ListBox1.DataSource = Nothing ListBox2.DataSource = Nothing Listbox1.ValueMember = Nothing 'added Listbox1.ValueMember = Nothing 'added ListBox1.Items.Clear() ListBox2.Items.Clear() m_DataSet.Tables.Clear() 'add this here, this will complete the clearing of data so you can restore it in the load_listbox call load_listbox() Else MsgBox("Reminder has not been removed") End If End Sub -
Listbox update with datasource
archer_coal replied to archer_coal's topic in Database / XML / Reporting
re I think I must not be using the best method to achieve this. The comments made on this problem seem to make sense in theory but for my program do not :p here is the code im toying with Private m_DataAdapter As OleDbDataAdapter Private m_DataSet As New DataSet() Private Sub load_listbox() m_DataAdapter = New OleDbDataAdapter( _ "SELECT * FROM reminders ORDER BY id", _ "Provider=Microsoft.Jet.OLEDB.4.0;" & _ "Data Source=C:\data\20304aa1.mdb") ' Fill the DataSet. m_DataAdapter.Fill(m_DataSet) ListBox1.DataSource = m_DataSet.Tables(0) ListBox2.DataSource = m_DataSet.Tables(0) ListBox1.ValueMember = "reminder" ListBox2.ValueMember = "id" End Sub 'Then the routine for deleting the item from the listbox Private Sub cmdDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdDelete.Click Dim testmsg As Integer Dim iVar As String iVar = ListBox2.SelectedItem(0) Label1.Text = iVar testmsg = MsgBox("Are you sure you want to remove this reminder?", 1, "Delete Reminder") If testmsg = 1 Then Dim myConnection As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\data\20304aa1.mdb") myConnection.Open() Dim MyCommand As New OleDbCommand("DELETE * FROM reminders where id = " & iVar, myConnection) MyCommand.ExecuteNonQuery() myConnection.Close() MyCommand.Dispose() ListBox1.DataSource = Nothing ListBox2.DataSource = Nothing ListBox1.Items.Clear() ListBox2.Items.Clear() load_listbox() Else MsgBox("Reminder has not been removed") End If End Sub After Listbox1 and 2 are set to nothing and are cleared, the previous items in the listboxes are replaced with System.Data.DataRowView -
I have a listbox bound to an oledb data connection with command buttons for delete and add. When the user selects an item and clicks on delete, the record is deleted fine but i cant get the listbox to show the changes without error. If i reload the listbox and its binding, it shows the previous items as well as the reloaded data. If i refresh the listbox nothing happens. If i try to use somthing like Listbox1.item.clear I get an error telling me i cannot clear when the datasource is set. How do i update the listbox to show the changes made after delete?
-
RE I thought of that but I'll be using an image for the background. Thanks for the input though.
-
RE Understanding WHY its doing what its doing would be great! If the code is faulty then help with fixing it would be great too. thnx My appologizes if the initial thread was not clear on that.
-
These are the things that drive me nuts. Want to join me for the ride? Great! Here's what you do. ( yes there is a question with this) Step 1. To a form add Panel1(set its borderstyle to FixedSingle) , 4 listboxes named lb1,lb2, lb3, lb4 and a button Step 2. Make the panel large enough to fit all 4 listboxes inside then place them inside the panel evenly spaced Step 3. Anchor the listboxes as follows: lb1 (Top,Left) lb2( Top, Right) lb3 (Bottom, Left) lb4 (Bottom, Right) Step 4. Make your form considerably larger than the panel Step 5. Add the following code to the button's click event Panel1.Height = Me.Height / 2 Panel1.Width = Me.Width / 2 lb1.Height = (Panel1.Height / 2) lb2.Height = (Panel1.Height / 2) lb3.Height = (Panel1.Height / 2) lb4.Height = (Panel1.Height / 2) lb1.Items.Add(lb1.Height) lb1.Items.Add(lb1.Width) lb1.Items.Add(Panel1.Height) lb1.Items.Add(Panel1.Width) lb2.Items.Add(lb2.Height) lb2.Items.Add(lb2.Width) lb3.Items.Add(lb3.Height) lb3.Items.Add(lb3.Width) lb4.Items.Add(lb4.Height) lb4.Items.Add(lb4.Width) lb1.Width = (Panel1.Width / 2) lb2.Width = (Panel1.Width / 2) lb3.Width = (Panel1.Width / 2) lb4.Width = (Panel1.Width / 2) Panel1.Refresh() Step 6. Scratch your head and wonder why the only listbox behaving correctly is lb1. The others seem to drift off into the seams of the panel even though they are anchord and should not. Anyone have an idea why this happens or did I take the short bus to school? I'm assuming the anchor fires before the button click and therefore the x,y Drawing points of the listboxes are etched in stone before the boxes are resized/redrawn? It should be a simple task to keep controls uniform in the event of resizing a form! :confused: :mad:
-
RE you could try a listbox binding to a listbox is tricky tho with the INSERT, UPDATE, DELETE routines
-
re thanks about the sign :) Im glad it worked out but yea i wish we could have learned what the trouble was.
-
re Thanks that worked nicely! :)
-
re Works rather nicely Thanks!
-
RE datagrid This is all ive found thus far on that subject add Imports System.Windows.Forms.DataGridTextBox 'create you custom colums and tablestyles and add Dim theCol As DataGridTextBoxColumn theCol.TextBox.Multiline = True Hope this helps