Inputbox () in Vb.net
-
Hi I am using inputbox function to set or get the column names and row names of datagridview , 1) when i call that function it shows the text of particular column or row ,If i make changes or not , then if i click OK it is showing the new name or or old name for datagridview col or row header . 2)
When i click Cancel,Then the problem arises ,If there is string in the textbox of inputbox() also it is returning the length of string as 0,Which is setting the column Text or Row text as "" .``So How can i maintain the text when the user presses cancel
Any Help in this .... DVS -
Hi I am using inputbox function to set or get the column names and row names of datagridview , 1) when i call that function it shows the text of particular column or row ,If i make changes or not , then if i click OK it is showing the new name or or old name for datagridview col or row header . 2)
When i click Cancel,Then the problem arises ,If there is string in the textbox of inputbox() also it is returning the length of string as 0,Which is setting the column Text or Row text as "" .``So How can i maintain the text when the user presses cancel
Any Help in this .... DVSThe most basic thing you can do, is simply check the length before you assign the new text to the row or column header. Current code is probably something like:
NewHeaderText = InputBox("blablabla") MyDataSet1.Tables(0).Columns(0).ColumnName = NewHeaderText
The alternative would be:NewHeaderText = InputBox("blablabla") If NewHeaderText.Length > 0 Then MyDataSet1.Tables(0).Columns(0).ColumnName = NewHeaderText End If
This way you catch an empty string, whether the user actually tried this, or whether he pressed cancel. JohanMy advice is free, and you may get what you paid for.
-
The most basic thing you can do, is simply check the length before you assign the new text to the row or column header. Current code is probably something like:
NewHeaderText = InputBox("blablabla") MyDataSet1.Tables(0).Columns(0).ColumnName = NewHeaderText
The alternative would be:NewHeaderText = InputBox("blablabla") If NewHeaderText.Length > 0 Then MyDataSet1.Tables(0).Columns(0).ColumnName = NewHeaderText End If
This way you catch an empty string, whether the user actually tried this, or whether he pressed cancel. JohanMy advice is free, and you may get what you paid for.
Dim iActiveCol As Integer = e.ColumnIndex Dim iActiveRow As Integer = e.RowIndex If iActiveRow = -1 Then If TypeOf sender Is DataGridView Then Dim sColumnName As String sColumnName = InputBox("Enter Column Name", "ColumnName", CType(ctr, DataGridView).Columns(iActiveCol).HeaderText) If sColumnName <> "" Then CType(ctr, DataGridView).Columns(iActiveCol).HeaderText = sColumnName CType(ctr, DataGridView).ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize Else ' CType(ctr, DataGridView).Columns(iActiveCol).HeaderText = sColumnName '' Here it is erasing the text if i make it clear the text in inputbox and cancel . How to handle this one . **Exit Sub** End If End If End If
Just observere the vb 6.0 adding a new tab There it is perfect how can i ge t that ??For1206
-
Dim iActiveCol As Integer = e.ColumnIndex Dim iActiveRow As Integer = e.RowIndex If iActiveRow = -1 Then If TypeOf sender Is DataGridView Then Dim sColumnName As String sColumnName = InputBox("Enter Column Name", "ColumnName", CType(ctr, DataGridView).Columns(iActiveCol).HeaderText) If sColumnName <> "" Then CType(ctr, DataGridView).Columns(iActiveCol).HeaderText = sColumnName CType(ctr, DataGridView).ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize Else ' CType(ctr, DataGridView).Columns(iActiveCol).HeaderText = sColumnName '' Here it is erasing the text if i make it clear the text in inputbox and cancel . How to handle this one . **Exit Sub** End If End If End If
Just observere the vb 6.0 adding a new tab There it is perfect how can i ge t that ??For1206
The trick is to simply not touch the HeaderText at all, if the value of sColumnName is an empty string.
If sColumnName <> "" Then CType(ctr, DataGridView).Columns(iActiveCol).HeaderText = sColumnName CType(ctr, DataGridView).ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize Else Exit Sub End If
Unless the code you posted is the only code in the sub, in that case you wouldn't even needElse Exit Sub
The code will simply run its course, never affecting the HeaderText of your column.My advice is free, and you may get what you paid for.