|
For i As Integer = 0 To ListBox1.Items.Count - 1
ListBox1.SetSelected(i, True)
Next i
SetSelected also allows you to deselect an item by setting the boolean parameter to false
|
|
|
|
|
How can I retrieve the list of IP Addresses, and the Names of the Computers connected in my local area Network.
I want to develop a project which can show me the list of computers connected to the server through vb.net.
Please Help me.
Sekhar
|
|
|
|
|
|
hi my name is Vuyiswa, i have the Following Problem
.
am using vb.net in vs2003. i have written an dabase application.i have knowledge of ADo.net and i have created my connection and droped the table on my form and generated the dataset. now when i add the new row to the dataset, it complete the process and be succsessfull, here is the code
<br />
'save the New Record for an Add or Edit<br />
If mblnAdding Then<br />
Try<br />
Dim newRow As DataRow = DataSet11._PROPERTY.NewRow<br />
newRow("Num_key") = txtnumkey.Text<br />
newRow("Extension") = txtextension.Text<br />
newRow("Cell_ID") = txtcellid.Text<br />
newRow("ACTUAL_EXTENT") = txtactualextent1.Text<br />
newRow("Lis_key") = txtliskey.Text<br />
newRow("Func_key") = txtfunckey.Text<br />
newRow("PROP_CATEGORY_ID") = txtcategoryid.Text<br />
newRow("Geocode") = txtgeocode.Text<br />
DataSet11._PROPERTY.Rows.Add(newRow)<br />
<br />
Catch exc As Exception<br />
MessageBox.Show("Unable to add the Record." & _<br />
ControlChars.NewLine & exc.Message, "Property")<br />
<br />
End Try<br />
mblnAdding = False<br />
lblRecordNumber.Text = "Record Added at the end of the Table"<br />
End If<br />
Locktextboxes()<br />
EnableNavigation()<br />
cmdsave.Enabled = False<br />
cmdadd.Text = "&Add"<br />
mblnIsDirty = True<br />
End Sub<br />
and my code is Very well working, i used the Closing Event of the form to update, meaning to save the dataset into the real table so as to reflect the new added row into my table, so i put the Following Code on the closing Event of my form
<br />
Private Sub frmSingle_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing<br />
'save the datasource Changes<br />
If mblnIsDirty Then<br />
If MessageBox.Show("Do you want to Save the Changes?", "Property", _<br />
MessageBoxButtons.YesNo, MessageBoxIcon.Question) = DialogResult.Yes Then<br />
Try<br />
SqlDataAdapter1.Update(DataSet11, "Property")<br />
Me.SqlDataAdapter1.Update(Me.DataSet11, "PROPERTY")<br />
<br />
Catch<br />
MessageBox.Show("Error saving the File", "Property")<br />
End Try<br />
End If<br />
End If<br />
End Sub<br />
Built it and run it ,after i click on the save Button of the first code, it save a new Row in the dataset. now when i try to close the form, it recognises the changes in the dataset and ask me if ai want to save the changes and i say "Yes" and it gives me the Error that used to trap Errors. as you have seen my above Errors, please help me and tell me what is wrong, why doesnt it update my dataset by appending a Row in the tables.
?
Vuyiswa
|
|
|
|
|
Vuyiswamb wrote: Try
SqlDataAdapter1.Update(DataSet11, "Property")
Me.SqlDataAdapter1.Update(Me.DataSet11, "PROPERTY")
Catch
MessageBox.Show("Error saving the File", "Property")
End Try
Get rid of the Try/Catch block for now and let the code throw the exception. We need to see the exception messsage to know what it's complaining about. Your code is hiding the exception behind a non-description messagebox that doesn't give any useful information.
|
|
|
|
|
thanks for your Reply Dave. here is the following Error i get when i remove the try and catch
"An unhandled exception of type 'System.Data.SQlClient.SQlException'
occurred in System.data.dll"
Please help
Vuyiswa
|
|
|
|
|
That's not the entire exception. What does the Message property say in that exception?
|
|
|
|
|
Hey
I have an application integrated with Microsoft Outlook 2003. This application also runs Macros in Excel and then saves the workbook. The save can take a reasonable amount of time, so at the moment I bring Excel to the front so the user can see the program hasnt crashed.
This is a bit of a bodge and looks untidy so is there a way to get Excel to notify my application of when it has finished saving?
I though about trying to hook into the Save event and then callback when it has done but I was wondering if there is a simpler way so that I can just implement a progress indicator or another way of telling the user the app is busy.
Thanks
Dan
|
|
|
|
|
I don't see how this is going to work. The Save method in the Excel object is going to be a blocking call, blocking your UI thread(!). So I don't see how you can put up a progress bar and update it while your UI thread is blocked.
|
|
|
|
|
You could use a BackgroundWorker that processes all the information in the background and reports back to your application the progress of the procedure. You would then have a progressbar update with the progress (you might consider a never-ending/repetitive progressbar if you cannot track the time of the save event).
Regards,
Thomas Stockwell
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
Visit my homepage Oracle Studios[ ^]
|
|
|
|
|
I recorded an actual Macro and it looks like this.
Application.CommandBars("Web").Visible = False
Range("A28").Select
Selection.Hyperlinks(1).Follow NewWindow:=False, AddHistory:=True
Range("A29").Select
ActiveWindow.SmallScroll Down:=3
What I actually have is thousands of rows populated, Three rows are visible with data in the top three rows of my active sheet, 26, 27 & 28 in this example.
When I first open the spreadsheet, I need to make the WEB toolbar go away, this part is good.
I then need to click on the very last hyperlink in 'A' column, I think it may be refered to something like lastused range????? This example is 'A28'.
I then need to put the cursor in the next available empty cell past the lastused range in the 'A' column and post it in the very top left corner, (as though it was in cell A1 ready to work).
This empty cell was in the fourth row so I did three smallscroll to get it to the top row in view.
When I record the macro as you see above it records the actual cell number, this will not help me but I know someone here can please.
I also need the macro to run slowly giving the internet time to upload the hyperlink and then revert back to finish the macro, it just zips right through it now and does not end up in the correct cell when completed.
Thanks in advance for any help, I didnt see a VBA forum, flame suit on.
Lastly, is there a way to make the WEB toolbar stay gone, it wasnt in view by default prior to some MS update I am guessing???
|
|
|
|
|
As I have said before I have textboxes bound to the DataGridView. When the user updates a value I have them click on a "Save" button where I get the values that find the row from the current row in the DataGridView and then call Row.BeginEdit, set the values, then call Row.EndEdit.
Only after sorting will the row change event occur (I am verifying this by checking for BindingSource.PositionChanged) and it only happens if I change the value within the sorted column and when it changes rows the row it changes to gets that single changed value.
This is so strange and Im not sure what to do about it.
CleaKO
"Now, a man would have opened both gates, driven through and not bothered to close either gate." - Marc Clifton (The Lounge)
|
|
|
|
|
Let's see the code that's making the changes. Why are you setting the values in the data in code? Why not just bind theTextBox to the fields?
|
|
|
|
|
Dave Kreskowiak wrote: Why are you setting the values in the data in code? Why not just bind theTextBox to the fields?
They are bound but I guess Im not sure how to apply those changes except for changing rows.
Dim searchKeys() As String = {value1, value2, value3}
Dim updateRow As DataRow = DsCirculars1.tblAPCirculars.Rows.Find(searchKeys)
Try
With updateRow
.BeginEdit()
.Item("FirstName") = uxFirstName.Text
.Item("LastName") = uxLastName.Text
.Item("Address") = uxAddress.Text
.Item("City") = uxCity.Text
.Item("State") = State.Text
.Item("ZipCode") = uxZipCode.Text
.EndEdit()
End With This does work when there is no column sorted and only causes the row to change if I change a value that is within that column.
CleaKO
"Now, a man would have opened both gates, driven through and not bothered to close either gate." - Marc Clifton (The Lounge)
|
|
|
|
|
OK. If the datagrid and the textboxes are both bound to the dataset in the same binding context, you don't need any of this code.
All it takes is something like this:
'
' Code to connect to database and fill a DataTable, or DataSet.
'
' Setup the bindings...
BindingSource1.DataSource = myDataTable
DataGridView1.DataSource = BindingSource1
SomeTextBox1.DataBindings.Add("Text", BindingSource1, "SomeColumnName")
SomeTextBox2.DataBindings.Add("Text", BindingSource1, "SomeColumn")
SomeTextBox3.DataBindings.Add("Text", BindingSource1, "OtherColumnName")
That's it, no other code to set anything really. Unless you're doing something that isn't so straight forward??
|
|
|
|
|
Dave Kreskowiak wrote: That's it, no other code to set anything really. Unless you're doing something that isn't so straight forward??
Im not doing anything that isnt straight forward but when the user types into the textbox, without moving to another row how is the data refreshed and saved without doing something like I did?
CleaKO
"Now, a man would have opened both gates, driven through and not bothered to close either gate." - Marc Clifton (The Lounge)
|
|
|
|
|
So long as the textbox's are bound in the same binding context, managed by the bindingsource) as the datagrid, you don't have to do anything. It happens automatically!
Try it! Start a new project. Create a form with a DGV and a couple of textboxs on it and add a bindingsource object to the form. Write some SQL to fill a datatable with a few columns of data and bind the BindingSource to the DataTable. Bind the DGV and the TextBox's to the BindingSource, like in my previous post, and try it! It might just surprise you.
|
|
|
|
|
I have Edit mode and Add mode, when the user chooses Add mode I clear the textbox bindings and when the user chooses Edit mode I use the following code.
uxFirstName.DataBindings.Add("Text", BindingSourceCirculars, "FirstName", True)
uxLastName.DataBindings.Add("Text", BindingSourceCirculars, "LastName", True)
uxAddress.DataBindings.Add("Text", BindingSourceCirculars, "Address", True)
uxCity.DataBindings.Add("Text", BindingSourceCirculars, "City", True)
uxState.DataBindings.Add("Text", BindingSourceCirculars, "State", True)
uxZipCode.DataBindings.Add("Text", BindingSourceCirculars, "ZipCode", True)
Unless I choose the find the row and edit it, nothing in the DataGridView changes until I change rows in the grid. Am I missing something? Binding seems to be much more complicated in 2.0 than it EVER was in 1.1 and I cant seem to find the information I need in order to make this work the way I want it to.
CleaKO
"Now, a man would have opened both gates, driven through and not bothered to close either gate." - Marc Clifton (The Lounge)
|
|
|
|
|
Is the real trick here to just call BindingSource.EndEdit in order to have that change applied if I am trying to have the user push a "Save" button for familiarity purposes?
CleaKO
"Now, a man would have opened both gates, driven through and not bothered to close either gate." - Marc Clifton (The Lounge)
|
|
|
|
|
Did ya try it? It's very possible that's all it's going to take. On top of that, maybe refreshing the DGV.
|
|
|
|
|
Can someone tell me the difference between these similar dataset writing routines?
The data writing subroutine:
Private Sub New_Bindings(ByVal intOrdinal As Integer, _
ByVal strCode As String, _
ByVal strName As String)
drCurrent = MyDataSet.Tables("tblBindings").NewRow()
drCurrent!Ordinal = intOrdinal
drCurrent!BindingCode = strCode
drCurrent!BindingName = strName
MyDataSet.Tables("tblBindings").Rows.Add(drCurrent)
Call Show_Changes("Sub New_Bindings", MyDataSet)
End Sub
After each row is written into the dataset I have another subroutine that prints out the results called Show_Changes.
Case one – The data is placed directly into the subroutine call.
I’m writing 5 rows to the dataset like this:
Call New_Bindings(1, "TST1", "Record 1")
Call New_Bindings(2, "TST2", "Record 2")
Call New_Bindings(3, "TST3", "Record 3")
Call New_Bindings(4, "TST4", "Record 4")
Call New_Bindings(5, "TST5", "Record 5")
Output screen results after each row addition:
Sub - Sub New_Bindings
TableName: tblBindings
1 TST1 1 Record 1
Sub - Sub New_Bindings
TableName: tblBindings
1 TST1 1 Record 1
2 TST2 2 Record 2
Sub - Sub New_Bindings
TableName: tblBindings
1 TST1 1 Record 1
2 TST2 2 Record 2
3 TST3 3 Record 3
Sub - Sub New_Bindings
TableName: tblBindings
1 TST1 1 Record 1
2 TST2 2 Record 2
3 TST3 3 Record 3
4 TST4 4 Record 4
Sub - Sub New_Bindings
TableName: tblBindings
1 TST1 1 Record 1
2 TST2 2 Record 2
3 TST3 3 Record 3
4 TST4 4 Record 4
5 TST5 5 Record 5
This works just fine. All the records have been written to the dataset and I can use the BindingNavigator control to go from record to record.
Case 2 – The data is placed into the subroutine via variables.
Call New_Bindings(CInt(txtOrdinal.Text), txtBindingCode.Text, txtBindingName.Text)
Output screen after the same five rows are added.
Sub - Sub New_Bindings
TableName: tblBindings
1 TST1 1 Record 1
Sub - Sub New_Bindings
TableName: tblBindings
1 TST2 2
2 TST2 2 Record 2
Sub - Sub New_Bindings
TableName: tblBindings
1 TST3 3
2 TST2 2 Record 2
3 TST3 3 Record 3
Sub - Sub New_Bindings
TableName: tblBindings
1 TST4 4
2 TST2 2 Record 2
3 TST3 3 Record 3
4 TST4 4 Record 4
Sub - Sub New_Bindings
TableName: tblBindings
1 TST5 5
2 TST2 2 Record 2
3 TST3 3 Record 3
4 TST4 4 Record 4
5 TST5 5 Record 5
As you can see the dataset is not the same. The method of data entry is the same except that case 2 uses variables instead of literals. Obviously .NET handles these two similar data entry methods differently, but I haven’t a clue as to how or why this occurs.
Here is the entire code for this one form:
Option Explicit On
Imports System.Data
Imports System.Data.OleDb
Imports System.Data.SqlTypes
Imports System.Data.SqlDbType
Imports System.Data.SqlClient
Public Class frmBindings
Dim Msg As String
Dim strSQL As String
'Declare the SQLDataAdapter and DataSet objects
Dim daBindings As New SqlDataAdapter()
Dim objCommandBuilder As New SqlCommandBuilder(daBindings)
Dim MyDataSet As New DataSet()
Dim changesDataSet As DataSet
Dim drCurrent As DataRow
Private Function Is_Filled_Out() As Boolean
Dim b1 As Boolean, b2 As Boolean, b3 As Boolean
If (txtOrdinal.Text = Nothing) Then
txtOrdinal.BackColor = Color.Yellow
b1 = False
Else
txtOrdinal.BackColor = Color.White
b1 = True
End If
If (txtBindingCode.Text = Nothing) Then
txtBindingCode.BackColor = Color.Yellow
b2 = False
Else
txtBindingCode.BackColor = Color.White
b2 = True
End If
If (txtBindingName.Text = Nothing) Then
txtBindingName.BackColor = Color.Yellow
b3 = False
Else
txtBindingName.BackColor = Color.White
b3 = True
End If
Is_Filled_Out = b1 And b2 And b3
End Function
Private Sub Clear_Form()
txtBindingID.Text = Nothing
txtBindingCode.Text = Nothing
txtBindingName.Text = Nothing
txtOrdinal.Text = Nothing
txtOrdinal.Focus()
End Sub
Private Sub Load_DataSet()
'Connect to the SQL Server database
Dim cn As SqlConnection = New SqlConnection(My.Settings. _
PrintsByMe_DevConnectionString)
cn.Open()
'Retrieve the data using a SQL statement
strSQL = "SELECT * FROM [tblBindings];"
Dim cd As New SqlCommand(strSQL, cn)
'Set the database connection for MySqlDataAdapter
daBindings.SelectCommand = cd
'Fill the DataSet and DataSet Schema
daBindings.MissingSchemaAction = MissingSchemaAction.AddWithKey
daBindings.FillSchema(MyDataSet, SchemaType.Source, "tblBindings")
daBindings.Fill(MyDataSet, "tblBindings")
'Close database connection
cn.Close()
MyDataSet.Tables(0).Columns("BindingID").AutoIncrement = True
MyDataSet.Tables(0).Columns("BindingID").AutoIncrementSeed = 1
MyDataSet.Tables(0).Columns("BindingID").AutoIncrementStep = 1
'Set the BindingNavigator's DataSource to the DataSet we created.
bsBindings.DataSource = MyDataSet
'Set the BindingSource Datamember to the table we are using.
bsBindings.DataMember = MyDataSet.Tables(0).TableName()
'Bind form control txtBindingID to the BindingID field
txtBindingID.DataBindings.Add("Text", bsBindings, "BindingID")
'Bind form control txtOrdinal to the Ordinal field
txtOrdinal.DataBindings.Add("Text", bsBindings, "Ordinal")
'Bind form control txtBindingCode to the BindingCode field
txtBindingCode.DataBindings.Add("Text", bsBindings, "BindingCode")
'Bind form control txtBindingName to the BindingName Field
txtBindingName.DataBindings.Add("Text", bsBindings, "BindingName")
End Sub
Private Sub New_Bindings(ByVal intOrdinal As Integer, _
ByVal strCode As String, _
ByVal strName As String)
drCurrent = MyDataSet.Tables("tblBindings").NewRow()
drCurrent!Ordinal = intOrdinal
drCurrent!BindingCode = strCode
drCurrent!BindingName = strName
MyDataSet.Tables("tblBindings").Rows.Add(drCurrent)
Call Show_Changes("Sub New_Bindings", MyDataSet)
End Sub
Private Sub btnClose_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles btnExit.Click
Me.Close()
End Sub
Private Sub frmBindings_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles MyBase.Load
Call Load_DataSet()
naviBindings.BindingSource = bsBindings
End Sub
Private Sub BindingNavigatorAddNewItem_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles BindingNavigatorAddNewItem.Click
Call New_Bindings(CInt(txtOrdinal.Text), txtBindingCode.Text, txtBindingName.Text)
Call Clear_Form()
End Sub
Private Sub BindingNavigatorUpdateDB_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles BindingNavigatorUpdateDB.Click
Dim intModified As Integer
Dim intAdded As Integer
Dim intRes As Integer
If MyDataSet.HasChanges(DataRowState.Modified Or DataRowState.Added) Then
changesDataSet = MyDataSet.GetChanges(DataRowState.Modified Or DataRowState.Added)
'Call Show_Changes(changesDataSet)
intModified = Modified_Records(changesDataSet)
intAdded = Added_Records(changesDataSet)
Msg = "You have modified " & CStr(intModified) & " records and " & _
"have added " & CStr(intAdded) & " records." & _
vbCRLF & "Do you wish to commit these changes to the database?"
intRes = MsgBox(Msg, MsgBoxStyle.Information + MsgBoxStyle.YesNo, "DataSet Changes")
If intRes = vbYes Then
'daBindings.Update(MyDataSet, "tblBindings")
Call Show_Changes("BindingNavagatorUpdateDB", changesDataSet)
Else
Msg = "Changes aborted." & vbCRLF & "The DataSet has NOT updated the database."
End If
End If
End Sub
Private Sub BindingNavigatorSaveNewItem_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles BindingNavigatorSaveNewItem.Click
If Is_Filled_Out() Then
Call New_Bindings(CInt(txtOrdinal.Text), txtBindingCode.Text, txtBindingName.Text)
Call Clear_Form()
Else
Msg = "Please fill in the highlighted box(es)."
MsgBox(Msg, MsgBoxStyle.Information + MsgBoxStyle.OkOnly)
End If
'txtOrdinal.Focus()
'Call New_Bindings(1, "TST1", "Record 1")
'Call New_Bindings(2, "TST2", "Record 2")
'Call New_Bindings(3, "TST3", "Record 3")
'Call New_Bindings(4, "TST4", "Record 4")
'Call New_Bindings(5, "TST5", "Record 5")
End Sub
End Class
Thanks,
Quecumber256
|
|
|
|
|
While you Post you got a warniing abt this message is too long?
so please post what is your problem on which line you got problem ?
Be specific to your question?
So that we can answer easily to solve your problem.
Regards,
Satips.
|
|
|
|
|
Satips:
I don't know exactly where the application fails. There are two different methods of entering data that should produce the same results, but don't.
Cleako asked for the code on Friday 1 Jun 07 when I first posted it. Today I reposted the question showing exactly what is happening and attached the code at the bottom of the letter so if some one needed the code they could look at it.
Do I need to get with Microsoft for a resolution to this problem?
Quecumber256
|
|
|
|
|
I asked for the Binding portion, I apologize for not getting back with you. I honestly dont know why you are having an issue with this because it looks correct, it looked correct before, and unless you changed it Im sure it's still correct. What you are doing is one of the most basic functions of ADO.NET.
CleaKO
"Now, a man would have opened both gates, driven through and not bothered to close either gate." - Marc Clifton (The Lounge)
|
|
|
|
|
Thank you for reassuring me I wasn't a dummy .
I attached the entire form class just in case there was an issue with the data binding portion or something else.
I have one other resource looking it over. If he can't find the problem then I'm being forced to use one of my complementry support intances.
Thank you,
Quecumber256
|
|
|
|
|