|
Hi, I bind a DataTable to a DataGrid. The DataGrid contains one column -- "Name". The DataTable has two columns -- "ID" and "Name". When the user selects a row in the DataGrid, how can I get the "ID" value from the DataTable?
Dim index As Integer = Me.dgdPersons.CurrentRowIndex
Dim oRow As DataRow = dsSearch.Person.Rows(index)
Dim ID As String = oRow("ID")
It works fine at the beginning, but if I click on the header of the "Name" column, the order of the rows is changed, and my code does not work then.
|
|
|
|
|
one way of doing this would be to give you're datagrid 2 columns and define the first column (ID) as index value or something like this (this will hide your column but you can still acces it from code)
another way would be to again make 2 columns but just make the width of the ID column 0
Hope this helps
|
|
|
|
|
Hi all,
I want be able to enable and disable navigation buttons when on the first or
last row of a DataGridView object.
I have a populated DataGridView and two buttons - "First Row" and "Previous Row"
If the user clicks "First Row", they are taken to the first row in the DataGridView via:
Private Sub btnFirstRecord_Click(...) <br />
' Move to first record in job list <br />
dgvMyRecords.CurrentCell = dgvMyRecords.Rows(0).Cells(0)<br />
End Sub
What I then want to to is disable the Prev Row button like this...
Private Sub dgvMyRecords_SelectionChanged(...)<br />
If dgvMyRecords.CurrentRow.Index = 0 Then <br />
btnPrevRow.Enabled = False<br />
Else <br />
btnPrevRow.Enabled = True <br />
End if <br />
End Sub
The problem is... this works if the user selects the first record using the mouse,
but not if the first record is selected through the code using CurrentCell.
If I click on the first row, SelectionChanged gets called AFTER the row gets changed.
If I set dgvMyRecords.CurrentCell to dgvMyRecords.Rows(0).Cells(0) (ie. select the first
row via code), SelectionChanged gets called, but BEFORE the row gets changed !?!?!?
Can anyone show me how to do this ?
cheers,
Matt.
|
|
|
|
|
Try using the DataGridView CellEnter event rather than the SelectionChanged event to toggle your navigation buttons.
|
|
|
|
|
Thanks Thomas... thats done the job nicely!
Still have issues with the SelectionChanged behaviour though, but you've given me a workaround...
cheers,
Matt.
|
|
|
|
|
A simple problem to solve I'd assume; I'm using MAPI to manipulate messaging. I have set up a profile in Outlook Express, and I can send email using my application. When I send to myself, it goes straight into my profile's inbox: Hotmail. However, When I use MAPIMessages1.MsgCount, it returns 0, as it reads from the default LOCAL folder. Any ideas on how to get my messages read from my new account?
|
|
|
|
|
why not use the system.net class. Alternatively, if you must use mapi, obviously you've set the custom folder or have it availabl;e in a variable, why not perform a manual message count with a loop or something.
Posted by The ANZAC : "WWBD, What Would Buffy Do?" : "I don't know man, she's stronger than me"
|
|
|
|
|
Thanks ANZAC, I think the problem lies in the way I've set my Outlook Express up as everything works well at work using Microsoft Outlook, but doesn't work with Express as I've got two folders: Local, and my default one.
|
|
|
|
|
i made a aql statement :
"select sum(fatrtot)reglz from reglz where fatrdate between '" + DateTimePicker1.Value + "'and'" + DateTimePicker2.Value + "'"<br />
and it's working well but there is sometimes gives me this number 10.233333333
how can i approximate it to nearest 10 or 100 plz tell me urgent
thanks
|
|
|
|
|
|
|
Then show the SQL statement and elaborate on the outcome
|
|
|
|
|
We have a SQL forum, you know.
The round function does obviously help you, because you can round off the number.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
How can i put a name for the datagride for the first row and then i want to put a spacifec value in the same coloum
examlpe
i want to put in the first row "vodafone" and under the word vodafone i want to put "20"
and then i was asking if there is to many number and i want to add them in one row as "total"and the total of them will be under this word "total"
thanks you all
|
|
|
|
|
Hi all:
Is there any way to make a particular item of the datagird unediatble ( ie a cell) ?
I'm using VB.NET 2003.
I'd appreciate your help in advance.
|
|
|
|
|
Hi, I was wondering if anyone could help me out w/ this. Ive been searching for days now and cannot find any information or help w/ this. I want to run specific programs within my vb.net application/form. I dont want the apps to launch separately from my form. I know theres a way to run them within the space of your vb.net form, because Ive seen it done before, but Im not sure what code/declaration to use.
Heres my code so far if it helps, Im using notepad just as an example:
Public Class Form1<br />
<br />
Private Sub AboutToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AboutToolStripMenuItem.Click<br />
MsgBox("Created by.....")<br />
End Sub<br />
<br />
Private Sub NotepadToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NotepadToolStripMenuItem.Click<br />
Start.Process("Notepad.exe", AppWinStyle.NormalFocus)<br />
End Sub<br />
End Class
Any help or tips would be great. Thank you
|
|
|
|
|
y2ktheory wrote: I know theres a way to run them within the space of your vb.net form
There kind of isn't, what makes you think otherwise ? You may be able to embedd an app by making it a child window of your form, but it wouldn't be clean, or recommended.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Sorry...I guess im not exactly sure. Ive seen an app made w/ vb that could run notepad, paint, and a few other simple things within that space. Ive also been told it can be done by someone else he said
"Some Applications offer ActiveX Controls which can be used by other applications in their programs (Such as Windows Media Player, MS Word etc.)
I'm not aware of a Notepad ActiveX Control so you will have to use a large text-box in your form and write the menu yourself"
If I wanted to make a child window in my form, how would I tell the program to output/display in that window? Would I use something like txtGetText.... or showdialog..., im just now sure how to get it to stay within the form =/
|
|
|
|
|
y2ktheory wrote: Some Applications offer ActiveX Controls which can be used by other applications in their programs (Such as Windows Media Player, MS Word etc.)
I'm not aware of a Notepad ActiveX Control so you will have to use a large text-box in your form and write the menu yourself"
OK, what this guy said was - "some applications have special controls written, which allow you to create instances of applications within your app. However, Notepad does not do this, so you basically have to write the ( incredibly simple ) functionality yourself"
y2ktheory wrote: If I wanted to make a child window in my form, how would I tell the program to output/display in that window?
If you did this, the window would not be in any way under the control of your application. Following the other guys advice, is more sensible. I did say it's not a good thing to do.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
alright, thanks for your help, I appreciate it
|
|
|
|
|
glad to help
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
On most controls there is a small black arrow in a white box that provides ways to quickly change properties of the control. How do I add additional properties to this tasks menu?
Posted by The ANZAC : "WWBD, What Would Buffy Do?" : "I don't know man, she's stronger than me"
|
|
|
|
|
I am very new to vb. I am trying to write an program which searches through all the word docs. in a directory.
I have a list of 20 stirngs I am looking for. I am sure only 1 of the strings is found in each file.
I have tried to write this several diferent ways but none works. I think I need two arrays and to loop through both and output the found strings, file names, and dates of the files to a spreadsheet.
Any help would be greatly appreciated.
Public Class Form1
'Create a list of doctors as an array.
'Create a list of files in the remote folder as an array
'Loop thru the “files array” and look for each doctor
'Write the doctor name, filedate, sysdate, and file name to a spreadsheet
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
' For Each strFile As String In My.Computer.FileSystem.Getectories("C:\batch")
'Add the item to the list
'ListBox1.Items.Add(strFile)
'If String.Compare(strDoc) Then
Dim doc1 As String = "ledford"
Dim list As System.Collections.ObjectModel.ReadOnlyCollection(Of String)
list = My.Computer.FileSystem.FindInFiles("C:\batch", doc1, True, FileIO.SearchOption.SearchTopLevelOnly)
For Each name As String In list
ListBox1.Items.Add(name)
Next
'End If
''''''Assign the files found in the list above as a variable and replace for file1.log
'Dim information As System.IO.FileInfo = My.Computer.FileSystem.GetFileInfo("C:\batch\file1.log")
'MsgBox("The file's full name is " & list.FullName & ".")
'MsgBox("Last access time is " & list.LastAccessTime & ".")
' Next
End Sub
'Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
' Dim arrayDocs (of string)
' arrayDocs(0) = "sexton"
' arrayDocs(1) = "wargo"
' arrayDocs(2) = "ledford"
' arrayDocs(3) = "koepke"
' For Each strDoc As String In arrayDocs
' ListBox2.Items.Add(strDoc)
' Next
'End Sub
End Class
-Kevin
|
|
|
|
|
This is how I might go about it. Hope it gives you the right idea.
Const directoryPath As String = "C:\test" ' The directory to look in
Dim desiredFiles As New List(Of String) ' List of files we're looking for
With desiredFiles ' Note I didn't use file extensions. Change that if you'd like.
.Add("File1") ' but you'll need to tweak the code below if you do.
.Add("File2")
End With
' METHOD 1
' Create a DirectoryInfo object for the desired directory
' to look in.
Dim info As New IO.DirectoryInfo(directoryPath)
' Get all the *.doc files in the directory
For Each file As IO.FileInfo In info.GetFiles("*.doc")
' The contains method is case sensitive. If you want a case-insentive
' search you can add the desired file names in all lower or uppercase and then use the
' ToLower or ToUpper methods on the file name
If desiredFiles.Contains(IO.Path.GetFileNameWithoutExtension(file.Name)) Then
' The file name was found in our list
MsgBox("Directory contained file: " & file.Name)
End If
Next
' METHOD 2
For Each file As String In desiredFiles
If IO.File.Exists(IO.Path.Combine(directoryPath, file & ".doc")) Then
MsgBox("Directory contained file: " & file)
End If
Next
|
|
|
|
|
how can i control the parallel port using visual basic??
coz' i would like to use my pc to be like a switch in a electronic door lock
but i don't know how to use the parallel port usnig the visual basic..
hope you can help guys.. thanks..
|
|
|
|