|
Thanks for the quick reply.
After looking at my code more closely, I was missing the following:
<br />
dgBtnCol.UseColumnTextForButtonValue = True
My code is now working.
Thanks.
|
|
|
|
|
Another workaround is to set the NullValue of the column to the desired text.
In a project of mine I have a DataGridView where the user can add rows manually. The text for the button didn't appear and nothing seemed to work. I then remembered that there is always a NullValue property and after I set this, the text appeared on the button
DataGridViewCellStyle8.NullValue = "Some Text"
Me.AddStillstand.DefaultCellStyle = DataGridViewCellStyle8
Me.AddStillstand.HeaderText = ""
Me.AddStillstand.Text = "Some Text"
Just in case someone else is having a similar issue
|
|
|
|
|
Hi,
I was pondering quite some time over this issue. The NullValue property did the trick
Thanks for posting this!
Kind regards,
Bob Stanneveld
|
|
|
|
|
The code is working. just make sure that you apply this after assigning the datasource to your grid control.
Step 1. After assign datasource to grid.
// Add a button column.
DataGridViewButtonColumn buttonColumn =
new DataGridViewButtonColumn();
buttonColumn.HeaderText = "";
buttonColumn.Name = "Status Request";
buttonColumn.Text = "Request Status";
buttonColumn.UseColumnTextForButtonValue = true;
dataGridView1.Columns.Add(buttonColumn);
step2.
just after adding the columns register your click event like below.
// Add a CellClick handler to handle clicks in the button column.
dataGridView1.CellClick +=
new DataGridViewCellEventHandler(dataGridView1_CellClick);
step 3.
now on below event,
void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
make sure which button is clicked when multiple are there.
if (e.RowIndex < 0 || e.ColumnIndex !=
dataGridView1.Columns["Status Request"].Index) return;
// Retrieve the task ID.
Int32 taskID = (Int32)dataGridView1[0, e.RowIndex].Value;
// Retrieve the Employee object from the "Assigned To" cell.
Employee assignedTo = dataGridView1.Rows[e.RowIndex]
.Cells["Assigned To"].Value as Employee;
========================
Ref: http://msdn.microsoft.com/en-us/library/ms171619.aspx[^]
hello give me code
|
|
|
|
|
Mate this was solved last year
As barmey as a sack of badgers
Dude, if I knew what I was doing in life, I'd be rich, retired, dating a supermodel and laughing at the rest of you from the sidelines.
|
|
|
|
|
Not really a visual basic problem, but i didnt know what forum to use, but my code is in vb.net
I have a program which has to print a bunch of documents, after printing a random number of documents this error is thrown: "Runtime.InteropServices.COMException (0x80010105): The server threw an exception. (Exception from HRESULT: 0x80010105 (RPC_E_SERVERFAULT)) "
I have written this testprogram which throws the same error
Imports wrd = Microsoft.Office.interop
...
Private Shared moapp As wrd.Word.Application
Private Shared odoc As wrd.Word.Document
...
Private Sub test()
moapp = New wrd.Word.ApplicationClass().Application
For i As Integer = 0 To 100
odoc = moapp.Documents.Add("\\bur-131.cmc.Be\Tools\INFORMATICA\ZZorg\bevestziek.doc")
moapp.Selection.GoTo(What:=wrd.Word.WdGoToItem.wdGoToBookmark, Name:="bwNaam")
With moapp.ActiveDocument.Bookmarks
.DefaultSorting = wrd.Word.WdBookmarkSortBy.wdSortByName
.ShowHidden = False
End With
moapp.Selection.TypeText(Text:="whoopie" & i.ToString())
sOriginalPrinter = moapp.ActivePrinter
moapp.ActivePrinter = "\\S31W40F\PRINT075"
With moapp.ActiveDocument.PageSetup
.FirstPageTray = 261 '257
.OtherPagesTray = 261 '257
End With
moapp.Application.PrintOut(FileName:="", Range:=wrd.Word.WdPrintOutRange.wdPrintAllDocument, Item:= _
wrd.Word.WdPrintOutItem.wdPrintDocumentContent, Copies:=1, Pages:="", PageType:=wrd.Word.WdPrintOutPages.wdPrintAllPages, _
ManualDuplexPrint:=False, Collate:=True, Background:=True, PrintToFile:= _
False, PrintZoomColumn:=0, PrintZoomRow:=0, PrintZoomPaperWidth:=0, _
PrintZoomPaperHeight:=0)
While moapp.BackgroundPrintingStatus = 0
End While
moapp.ActivePrinter = sOriginalPrinter
odoc.SaveAs("C:\somelocation\temp.doc")
odoc.Close()
Next
System.Runtime.InteropServices.Marshal.ReleaseComObject(odoc)
odoc = Nothing
moapp.Quit()
System.Runtime.InteropServices.Marshal.ReleaseComObject(moapp)
moapp = Nothing
GC.Collect()
GC.WaitForPendingFinalizers()
End Sub
Sometimes it throws the error when opening the document, the other time when printing the document..
The problem occurs on a Vista Enterprise SP1, Office 2003 and only on a HP Laserjet 2430dtn printer. On another type of printer the code runs perfect, also on a win2000 the code runs perfect. I tried installing other drivers for this printer, same problem...
Does anyone have an idea what i can try to solve or work around this problem. I know my code works when i close word and close the document and call the garbagecollector for each document, but then it takes about 17 seconds per document to print out...
If i don't print at all it also works
Thanks in advance.
|
|
|
|
|
Hi,
I am new to Visual Basic 2005. I need help in displaying the hierarchical data from the database in treeview and also update the tables back when a new node is added/deleted. I am using Oracle as background. Please help me to get some study material or sample code.
|
|
|
|
|
How can I validate that a user has entered a correct phone number into a text box? The existing form uses a textbox to input the phone number. Apparently the only valid entries are in the following form: xxx-xxx-xxxx
I am not sure how to pass values into a procedure or function.
Can someone help?
Thank you
|
|
|
|
|
If you are using VB.NET, you can use "regular expressions" to validate your field matches a particular format... if you are using VB6 (why??), then you will need to have an event behind your form that passes the textbox's value to a function for parsing.
|
|
|
|
|
As Damian S said, you can use regular expressions in VB.Net. Try this function :
Private Function ValidatePhoneNumber(ByVal StringToTest As String) As Boolean
Dim expression As New Regex("(\(\d{3}\)|\d{3})[- ]\s?\d{3}[- ]\d{4}")
Dim match As Match = expression.Match(StringToTest)
If match.Success Then
Return True
Else
Return False
End If
End Function
Then you can call your function like this :
If TextBox1.Text <> String.Empty Then
If ValidatePhoneNumber(TextBox1.Text) Then
MsgBox("Correct phone number.")
Else
MsgBox("Not valid phone number")
End If
End If
If you want to learn more about regular expressions then I recommend you download a copy of Expresso (google it). It is an excellent tool for learning them.
Hope this helps.
|
|
|
|
|
Thank you Damian. I will try your example and look at regular expressions.
|
|
|
|
|
Regular expressions are the best way to go, as you can then embed some real phone number rules such as area code validation and so on.
Alternatively if you are only dealing with the one format allowed then I suggest you use a masked textbox so the end user can't even enter the wrong format.
|
|
|
|
|
Thanks Napolean Solo.
I will try regular expressions.
|
|
|
|
|
I'm using Visual Studio 2008 to develop a web site for my daughter's softball league. In one page I have two RadioButtonLists in the same panel in their own table cells. I programatically build the RBLs and determine the initial selected index values for each. The behavior I'm seeing is as follows:
1. I sucessfully change the first selected index from its cleared
state (-1) to the value I calculated. The second RBL remains in
its clear state (as it should).
2. I then set the second RBL's selected index. While its value is
correctly set, the first RBL's selected index is also altered
to the same value simulataneously.
I've stepped through with the VS debugger and watched these two steps occur as described.
Is this a known faux pas on my part? If so what have I done wrong?
Otherwise, has anyone else seen similar behavior?
I'm not sure what to include here so I'll probably provide too much of some detail and not enough of other, but I'll gladly provide the entire aspx file (imbedded VB script plus a common function VB scrip "include") and/or screen captures of the variable states as I stepped through the code, if any of these would be of use.
Please don't make fun of my choice of style!
PLEASE NOTE: Even though I'm including the related event handler routines, the erroneous behavior occurs on page load before any user selections are made.
Detail below.
Thanks in advance,
John
#########################################################################################
Page Content:
<tr>
<td> </td>
<td align="left">
<asp:RadioButtonList ID="hTeamNameRBL" runat="server" Enabled="False" OnSelectedIndexChanged="selectedHomeTeamChanged" AutoPostBack="True"></asp:RadioButtonList>
</td>
<td> </td>
<td align="left">
<asp:RadioButtonList ID="aTeamNameRBL" runat="server" Enabled="False" OnSelectedIndexChanged="selectedAwayTeamChanged" AutoPostBack="True"></asp:RadioButtonList>
</td>
<td> </td>
<td align="left" valign="top">
<asp:RadioButtonList ID="fieldRBL" runat="server" Width="200px" style="text-align:left;" Enabled="False" OnSelectedIndexChanged="selectedFieldChanged" AutoPostBack="True"></asp:RadioButtonList>
<asp:TextBox ID="otherField" runat="server" Enabled="false" OnTextChanged="otherFieldTextChanged" AutoPostBack="True"></asp:TextBox>
</td>
<td> </td>
</tr>
#########################################################################################
RadioButton Contructor Routine:
PLEASE NOTE:: The common function call...
myCommonVB.getTeamNamesByDiv(myYear, division, teamNames, teamNumbers, teamLetters, errEncountered, errDetail)
Takes (ByVal) integer "year" and "division" values and returns (ByRef) string arrays of teamNames, teamNumbers and teamLetters (pulled from a database), as well as error information if any.
Sub buildTeamRBL(ByVal division As Integer, Optional ByVal myYear As Integer = 2010)
Dim teamNames As String() = Nothing
Dim teamNumbers As String() = Nothing
Dim teamLetters As String() = Nothing
Dim lItem As New ListItem()
Dim tnLen As Integer = 0
Dim hTeamSelected As Integer = -1
Dim aTeamSelected As Integer = -1
hTeamNameRBL.Enabled = True
aTeamNameRBL.Enabled = True
hTeamNameRBL.Items.Clear()
aTeamNameRBL.Items.Clear()
hTeamNameRBL.ClearSelection()
aTeamNameRBL.ClearSelection()
myCommonVB.getTeamNamesByDiv(myYear, division, teamNames, teamNumbers, teamLetters, errEncountered, errDetail)
If Not errEncountered Then
tnLen = teamNames.GetUpperBound(0)
For i As Integer = 0 To tnLen - 1
lItem = New ListItem()
lItem.Text = teamNames.GetValue(i)
lItem.Value = lItem.Text
aTeamNameRBL.Items.Add(lItem)
If lItem.Text.Equals(aTeamName) Then
aTeamSelected = i
aTeamNumber = teamNumbers(i)
aTeamLetter = teamLetters(i)
End If
hTeamNameRBL.Items.Add(lItem)
If lItem.Text.Equals(hTeamName) Then
hTeamSelected = i
hTeamNumber = teamNumbers(i)
hTeamLetter = teamLetters(i)
End If
Next
aTeamNameRBL.SelectedIndex = aTeamSelected
hTeamNameRBL.SelectedIndex = hTeamSelected
Else
debug.Text += errDetail
End If
End Sub
#########################################################################################
OnSelectedIndexChanged routines:
FYI: The following two ensure the alternate RBL doesn't have the same selected value.
Sub selectedHomeTeamChanged(ByVal sender As Object, ByVal e As System.EventArgs)
Dim orgAteamSelectedIndex As Integer = aTeamNameRBL.SelectedIndex
Dim newHteamSelectedIndex As Integer = hTeamNameRBL.SelectedIndex
For i As Integer = 0 To teamNames.GetUpperBound(0) - 1
aTeamNameRBL.SelectedIndex = i
aTeamNameRBL.SelectedItem.Enabled = True
Next
aTeamNameRBL.SelectedIndex = newHteamSelectedIndex
aTeamNameRBL.SelectedItem.Enabled = False
If Not orgAteamSelectedIndex = -1 Then
aTeamNameRBL.SelectedIndex = orgAteamSelectedIndex
Else
aTeamNameRBL.ClearSelection()
End If
seeIfEnablingSubmit()
End Sub
Sub selectedAwayTeamChanged(ByVal sender As Object, ByVal e As System.EventArgs)
Dim orgHteamSelectedIndex As Integer = hTeamNameRBL.SelectedIndex
Dim newAteamSelectedIndex As Integer = aTeamNameRBL.SelectedIndex
For i As Integer = 0 To teamNames.GetUpperBound(0) - 1
hTeamNameRBL.SelectedIndex = i
hTeamNameRBL.SelectedItem.Enabled = True
Next
hTeamNameRBL.SelectedIndex = newAteamSelectedIndex
hTeamNameRBL.SelectedItem.Enabled = False
If Not orgHteamSelectedIndex = -1 Then
hTeamNameRBL.SelectedIndex = orgHteamSelectedIndex
Else
hTeamNameRBL.ClearSelection()
End If
seeIfEnablingSubmit()
End Sub
|
|
|
|
|
at the 1st line of the Procedure "selectedHomeTeamChanged"
Check for
If not page.isPostBack=true Then
'''''' write your code'''''''''
End If
Arindam Banerjee
Sr. Software Developer
Rance Computer Pvt Ltd.
Kolkata (India)
|
|
|
|
|
Hi Arindam.
Thanks very much for your reply.
I tried your suggestion w/o success. I did so even I saw (by stepping through with the debugger) the errant behavior occur on and between the two distinct "steps":
1. aTeamNameRBL.SelectedIndex = aTeamSelected
2. hTeamNameRBL.SelectedIndex = hTeamSelected
If it would be of use to anyone I have screen captures showing the fact that after step 1. is executed, the SelectedIndex of both RadioButtonList's are set to the "aTeamSelected" value, and then after step 2. both are set to the "hTeamSelected" value.
Also, I'd be happy to grab whatever additional debug detail you might suggest.
As I've seen Visueal Studio occasionally wrap itself around the axle and not register the fact changes have been made I also tried...
a. Deleting and recreating the RBLs
b. Deleting the RBs, saving the file, closing the project and then recreating them
c. Renaming them
None of these attemps made any difference. As soon as the first RBL was adjusted, the second was as well, and vice-versa.
HELP!!!!
|
|
|
|
|
Hello ! why i can't catch event keydown in a form that contain a datagridview. i have use KeyPreview= true in form load. but i still can't get any keydown value after pressing key. please give me some advise
|
|
|
|
|
See here[^].
Me, I'm dishonest. And a dishonest man you can always trust to be dishonest. Honestly. It's the honest ones you want to watch out for...
|
|
|
|
|
|
I tried and works fine for me.
|
|
|
|
|
Hi all,
I have an issue with a datagrid in VB 2008 Express. I have loaded an Excel file into a datagrid as a preview; now I want to insert the datagrid content into a table in an Oracle DB (tha table have the same fields of the excel file). How ca I do it? I have tried with the following code but doesn't work
Using connection As New OleDbConnection(connectionString)
Dim adapter As New OleDbDataAdapter()
adapter.InsertCommand = New OleDbCommand(queryString, connection)
Dim builder As OleDbCommandBuilder = New OleDbCommandBuilder(adapter)
connection.Open()
adapter.Fill(data)
adapter.Update(data, tableName)
Return data
End Using
When VB try to execute this command
adapter.Fill(data)
it crash with vshost error. If I Delete this row the functon works, but I haven't the data into the table.
Is there anyone can help me?
Many thanks
Filippo
|
|
|
|
|
What is the error message?
|
|
|
|
|
"vshost.exe has stopped working" and the application crash
|
|
|
|
|
Hi tried also to cicle into the rows/cols into the Datase with the following instruction
Dim iRow As Integer
Dim iCols As Integer
Dim sriga As String
For iRow = 0 To dgvPreview.RowCount
For iCols = 0 To dgvPreview.ColumnCount
If Len(sriga) = 0 Then
sriga = dgvPreview.Rows(iRow).Cells(iCols).Value.ToString
Else
sriga = sriga & ", " & dgvPreview.Rows(iRow).Cells(iCols).Value.ToString
End If
Next
TextBox2.Text = TextBox2.Text & vbCrLf & sriga
TextBox2.Refresh()
sriga = ""
Next
But the finel result is the same The Vb crash with the same vshost error
Please Help me! I'm going mad!
|
|
|
|
|
Try the following:
For iRow = 0 To dgvPreview.RowCount - 1
For iCols = 0 To dgvPreview.ColumnCount - 1
(Note the additional "- 1" at the end of the lines)
Maybe it is also helpful for your further devolpments to use try-catch-blocks, to handle exceptions. Normally the Exception itself contains several useful information, which could help you to identify the error's position and circumstances.
|
|
|
|
|
Well, first of all, I don't think you're understanding how ADO.Net works.
I suggest starting here: Overview of ADO.NET[^].
The InsertCommand that you are creating is used to run a SQL Insert...or in other words to insert a record into a database. And, the InsertCommand is only used when running an Update where records are marked as added or if you say InsertCommand.ExecuteNonQuery() .
If you are trying to fill a table, you need to change the way you are setting up the table. I suggest looking at: OleDBDataAdapter Class[^]
You want to change it to provide a SelectCommand. Generally, you do this like:
newDataAdapter = New OleDb.OleDbDataAdapter(sql, connectionString)
newDataAdapter.Fill(ProjectDS, "ProjectInfo")
I would say you clearly haven't looked at how to use ADO.NET and you need to start there.
|
|
|
|