|
Simon_Whale wrote: Runs with no errors but the text doesn't show up. Any ideas?
Yup, you set the HeaderText [^] property to Nothing . Try something like this;
buttonColumn.HeaderText = "Hello World"
I are Troll
|
|
|
|
|
|
You're right. I've taken the example, compiled it using SharpDevelop, the example shows the exact same code;
Dim buttonColumn As New DataGridViewButtonColumn()
buttonColumn.HeaderText = ""
buttonColumn.Name = "Status Request"
buttonColumn.Text = "TestText"
buttonColumn.UseColumnTextForButtonValue = True The HeaderText is the caption of the column, my bad. And yes, this code should have changed the caption of the button within the buttoncolumn.
It seems that the example works. Can you post your version of the code?
I are Troll
|
|
|
|
|
Thanks for this Ed
Private Sub Properties_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
'set the screen size according to values in the app.config
Me.Width = My.Settings.x
Me.Height = My.Settings.y
'load in the list of countries they can use
'Dim cList As New List(Of ClientHome.vb.Countries)
'Dim x As New ClientHome.vb.Buildings
'cList = x.Countries
'cbCountries.DataSource = cList
'x = Nothing
'expiry date
'dtBldExpiry.Value = DateAdd(DateInterval.Day, 365, dtBldStart.Value)
'dtCntExpiry.Value = DateAdd(DateInterval.Day, 365, dtCntStart.Value)
'the question textbox in the grid
Dim xy As New DataGridViewTextBoxColumn
xy.HeaderText = "Question"
Me.DataGridView1.Columns.Add(xy)
'drop down list on grid
Dim xx As New DataGridViewComboBoxColumn
xx.Name = "YesNo"
xx.Items.Add("Yes")
xx.Items.Add("No")
Me.DataGridView1.Columns.Add(xx)
'the Answer Question
Dim yx As New DataGridViewTextBoxColumn
yx.HeaderText = "Answer"
Me.DataGridView1.Columns.Add(yx)
'the view button
' Add a button column.
Dim buttonColumn As New DataGridViewButtonColumn()
buttonColumn.Name = "Requests"
buttonColumn.Text = "Requests"
buttonColumn.UseColumnTextForButtonValue = True
DataGridView1.Columns.Add(buttonColumn)
End Sub
thats it Ed, there is a datagridview control on the form
Many Thanks
Simon
|
|
|
|
|
Simon_Whale wrote: there is a datagridview control on the form
With or without the correct caption on the buttons? I'll send my version by mail
I are Troll
|
|
|
|
|
There is no captions on the button for the code i sent but im after putting a caption on the button for the users to press
once again many thanks for your help
SImon
|
|
|
|
|
Ed,
Thank you, you are a genius worked out the problem from your example.
During my experimentation / design layouts i wasn't adding a datasource to the grid. so it was displaying the first empty row.
I then created a simple list of integers and set that to the datasource of the datagridview and the text shows up on the button as expected.
could you assume this is how its suppose to work?
Many Thanks
Simon
|
|
|
|
|
Simon_Whale wrote: Thank you, you are a genius worked out the problem from your example.
Glad that it helped, but you're the one who worked it out
Simon_Whale wrote: I then created a simple list of integers and set that to the datasource of the datagridview and the text shows up on the button as expected.
could you assume this is how its suppose to work?
It's one way that it can work - there's a lot of ways to fill a datagridview. And yes, it would be a good way; it's easy to read, easy to comprehend and thus, easy on maintenance.
I are Troll
|
|
|
|
|
I'm having the same problem. I read the postings, but I don't understand how this was solved.
Here is my code snipet:
Dim dgBtnCol As New DataGridViewButtonColumn()
dgBtnCol.Name = "SelBtn"
dgBtnCol.Text = "Select"
DataGridView1.Columns.Add(dgBtnCol)
Me.DataGridView1.DataSource = DT ' The datatable is already populated with data at this point
The grid displays, but the caption on the button is nothing. How did the original poster solve this ?
I forgot to add the following line of code ....
<br />
dgBtnCol.UseColumnTextForButtonValue = True
Regards,
David
|
|
|
|
|
Below is what i have working in a project
Private Sub CreateGrid(ByRef data As DataView)
'the questionno
Dim BrokerNo As New DataGridViewTextBoxColumn
BrokerNo.HeaderText = "Broker Ref"
BrokerNo.DataPropertyName = "brokerref"
BrokerNo.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill
Me.DataGridView1.Columns.Add(BrokerNo)
'the question textbox in the grid
Dim BrokersName As New DataGridViewTextBoxColumn
BrokersName.HeaderText = "Broker Name"
BrokersName.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill
BrokersName.DataPropertyName = "brokername"
Me.DataGridView1.Columns.Add(BrokersName)
'drop down list on grid
Dim BrokerStatus As New DataGridViewTextBoxColumn
BrokerStatus.DataPropertyName = "status"
BrokerStatus.HeaderText = "Status"
BrokerStatus.Name = "Status"
Me.DataGridView1.Columns.Add(BrokerStatus)
'the Answer Question
Dim Address As New DataGridViewTextBoxColumn
Address.Name = "Address"
Address.DataPropertyName = "address"
Address.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill
Me.DataGridView1.Columns.Add(Address)
Dim TelNo As New DataGridViewTextBoxColumn
TelNo.HeaderText = "Tel No"
TelNo.DataPropertyName = "telno"
TelNo.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill
Me.DataGridView1.Columns.Add(TelNo)
Dim buttonColumn As New DataGridViewButtonColumn()
buttonColumn.HeaderText = "View"
buttonColumn.Text = "View"
buttonColumn.UseColumnTextForButtonValue = True
buttonColumn.AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells
buttonColumn.FlatStyle = FlatStyle.Standard
DataGridView1.Columns.Add(buttonColumn)
DataGridView1.AlternatingRowsDefaultCellStyle.BackColor = Color.LightGreen
DataGridView1.DataSource = data
End Sub
As barmey as a sack of badgers
|
|
|
|
|
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)
|
|
|
|