Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Inputbox () in Vb.net

Inputbox () in Vb.net

Scheduled Pinned Locked Moved Visual Basic
helpcsharpquestion
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    VB 8 0
    wrote on last edited by
    #1

    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

    J 1 Reply Last reply
    0
    • V VB 8 0

      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

      J Offline
      J Offline
      Johan Hakkesteegt
      wrote on last edited by
      #2

      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. Johan

      My advice is free, and you may get what you paid for.

      F 1 Reply Last reply
      0
      • J Johan Hakkesteegt

        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. Johan

        My advice is free, and you may get what you paid for.

        F Offline
        F Offline
        for1206
        wrote on last edited by
        #3

        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

        J 1 Reply Last reply
        0
        • F 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

          J Offline
          J Offline
          Johan Hakkesteegt
          wrote on last edited by
          #4

          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 need Else 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.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups