Wednesday, 21 August 2013

Remove the highlighting from combobox when selected

To remove the highlight from a selected item in a combo box:

ComboBox1.SelectedIndex = -1

Friday, 14 June 2013

How to make a pop up window in vb.net

HI user you can make popup window by writing that piece of code
here FrmProviderMedicationsis name of form which you open as pop window

 Dim obj As New FrmProviderMedications()
                obj.ShowDialog()

Regards:
Ahmad Khalid
Software Engineer

Convert String rgb to color IN VB.NET

Hi user  i solve that problem by using that piece of code .here NOTE_STATUS_COLOUR is string in which color is save i convert into color in this way.and put in background of row color in ultragrid

If e.Row.Cells("NOTE_STATUS_COLOUR").Value IsNot Nothing Then
  Dim noteColor As Color =System.Drawing.Color.FromName(CStr(e.Row.Cells("NOTE_STATUS_COLOUR").Value).Trim)
            e.Row.Appearance.BackColor = noteColor
            e.Row.Appearance.BackColor2 = noteColor
        End If


Thursday, 13 June 2013

disable(readonly) all control of a form(window) from other window in vb.net

Hi  i  made all control except close button disable all read only in this way. my all control in the panel and i disable all that and also made disable all toolbar control


Private Sub FrmTodoList_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

  If IsReadOnly Then
            DisableAll()
        End If
    End Sub

 Private Sub DisableAll()
        Me.PnlCSDetail.Enabled = False
        For Each tool As Infragistics.Win.UltraWinToolbars.ToolBase In Me.TBMCSDetail.Toolbars(0).Tools
            If Not tool.Key.ToLower.Equals("dclose") Then
                tool.SharedProps.Visible = False
                tool.SharedProps.Enabled = False
            End If
        Next

 Public Property IsReadOnly() As Boolean
        Get
            Return _isReadOnly
        End Get
        Set(ByVal value As Boolean)
            _isReadOnly = value
        End Set
    End Property
Regards:
Ahmad Khalid
Software Engineer

Wednesday, 12 June 2013

Prevent From Duplicate Record editing in Ultragrid

I Resolve this Problem By using That Type of Check

  Dim frmdrug As New frmDrugSearch
                If Cbxprovider.Text = Nothing Then
                    MessageBox.Show("Please Select the Provider First.........")
                Else
                    Dim rw As UltraGridRow = Cbxprovider.SelectedRow()

                    If frmdrug.ShowDialog(ListFormOpenMode.SelectionOnly) = Windows.Forms.DialogResult.OK Then
                        If dsView.Tables(0).Select("DRUG_NDC = '" + frmdrug.DRUG_NDC + "' AND PROVIDER_ID = " + selectedProvider + " ").Length = 0 Then
                            Dim newRow As DataRow = dsView.Tables(0).NewRow
                            newRow("DRUG_ID") = frmdrug.MEDICATION_ID
                            newRow("DRUG_NDC") = frmdrug.DRUG_NDC
                            newRow("DRUG_NAME") = frmdrug.BRAND_NAME
                            newRow("ACTIVE") = True
                            newRow("PROVIDER_ID") = selectedProvider
                            dsView.Tables(0).Rows.Add(newRow)
                        Else
                            MessageBox.Show("Selected Grug Already Exists", "Add")
                        End If

                    End If

Wednesday, 29 May 2013

ultra grid control helps and setting code

code for displaying delete conformation 


  Dim row As UltraGridRow

                If CSMsgBox.ShowQuestionMessage("Do you want to delete the data on the grid?", MessageBoxButtons.YesNo) = Windows.Forms.DialogResult.Yes Then

                    For Each row In Me.UltraGrid1.Selected.Rows

                        row.Delete(False)

                        Me.UltraGrid1.UpdateData()
                    Next
                End If

code for displaying checkbox and text after check box click in ultra grid

 Dim chk As New Infragistics.Win.UltraWinEditors.UltraCheckEditor

 Me.UltraGrid1.DisplayLayout.Bands(0).Columns("ACTIVE").Style = ColumnStyle.CheckBox
        Me.UltraGrid1.DisplayLayout.Bands(0).Columns("ACTIVE").Editor = chk.EditorUltraGrid1.DisplayLayout.Bands(0).Override.CellDisplayStyle = CellDisplayStyle.FormattedText

Ultra Grid: Remove/Change selected Row color


If you want to remove selected row color(by default blue) and preserve your cell colors, follow this procedure.

Private Sub grid1_InitializeLayout(ByVal sender As System.Object, ByVal e As Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs) Handles ultragrid.InitializeLayout

'Make selected row color to transparant
e.Layout.SelectionOverlayColor = SystemColors.Highlight
'remove slected and active appearance
With e.Layout.Bands(0)
.Override.SelectedAppearancesEnabled = DefaultableBoolean.False
.Override.ActiveAppearancesEnabled = DefaultableBoolean.False
End With

End Sub

code for Auto_fitting columns to ultraGrid's width
first of all import this

Imports Infragistics.Win.UltraWinGrid
Then
Me.UltraGrid1.DisplayLayout.AutoFitStyle = AutoFitStyle.ResizeAllColumns

code for Ultra Grid to select an entire row when a cell is clicked

UltraGrid1.DisplayLayout.Override.CellClickAction = Infragistics.Win.UltraWinGrid.CellClickAction.RowSelect
code for Ultra Grid, how to lock cell data - disable editing
' Disable updating on the entire grid
Me.ultraGrid1.DisplayLayout.Override.AllowUpdate = DefaultableBoolean.False



' Enable updating on the root band. This will override the DisplayLayout setting
Me.ultraGrid1.DisplayLayout.Bands(0).Override.AllowUpdate = DefaultableBoolean.False



Code for Multi selection off
 e.Layout.Override.SelectedAppearancesEnabled = DefaultableBoolean.False

If u want on then simply write true in place of false on above line

Code for ADD New Row
if you want at row on buttom then do this
UltraGrid.displaylayout.Override.AllowAddNew=AllowAddNew.FixedAddRowOnBottom

if you want at row on top then do this
UltraGrid.displaylayout.Override.AllowAddNew=AllowAddNew.FixedAddRowOnTop

and so on many properties please explore it

Code for Row Selector
Me.UltraGrid.displaylayout.Bands(0).Override.RowSelectors=DefaultableBoolean.True


Code for delete row from database

Me.UltraGrid.ActiveRow.Delete()

Code for Color the specific column
 in ultragrid InitializeRow event
  e.Row.Cells("cell name here").Appearance.BackColor = Color.Green


Code for Hide row selectors:

in ultragrid InitializeLayout event
e.Layout.Override.RowSelectors = DefaultableBoolean.False

Code for Column Sorting Disable

in ultra grid Initialize Layout event

e.layout.Override.HeaderClickAction = HeaderClickAction.Select
e.layout.Override.SelectTypeCol = SelectType.None


Hide group header box:
In ultra grid grid Initialize Layout

e.Layout.GroupByBox.Hidden = True

code for Hide row selectors:
In ultragridgrid InitializeLayout event

e.Layout.Override.RowSelectors = DefaultableBoolean.False

three properties of the override that control ' on the Override off the DisplayLayout, then these settings apply to the whole ' UltraGrid.

'FOR MODIFY ALLOW OR UPDATE IN ULTRAGRID
Me.ultraGrid1.DisplayLayout.Override.AllowUpdate = DefaultableBoolean.True

'FOR adding and delecting in ultragrid

      Me.ultraGrid1.DisplayLayout.Override.AllowAddNew = AllowAddNew.No
      Me.ultraGrid1.DisplayLayout.Override.AllowDelete = DefaultableBoolean.False

     ' You can set them on a specific band as well. These settings override those
      ' set on the DisplayLayout's Override object for this band.
   Me.ultraGrid1.DisplayLayout.Bands(0).Override.AllowUpdate = DefaultableBoolean.True
      Me.ultraGrid1.DisplayLayout.Bands(0).Override.AllowAddNew = AllowAddNew.No
      Me.ultraGrid1.DisplayLayout.Bands(0).Override.AllowDelete = DefaultableBoolean.False

 ' There are Activation properties on row, column and cells that dictate whether 
      ' associated cells can be modified, or can even enter in edit mode.
  Dim column As UltraGridColumn = Me.ultraGrid1.DisplayLayout.Bands(0).Columns("CustomerID")
      Dim row As UltraGridRow = Me.ultraGrid1.Rows(0)

' Set the CellActivation off the column something other than AllowEdit to prevent
  ' the user from modifying cells in that column. ActivateOnly allows the user to 
  ' go into edit mode so the user can select and copy text, however the cell will
      ' be read-only thus preventing any data modification.
      column.CellActivation = Activation.ActivateOnly

      ' You can override cell activation setting for a particular row. 
      row.Activation = Activation.ActivateOnly

      ' Furthermore you can override activation on a cell as well.
      row.Cells(column).Activation = Activation.AllowEdit


 code for Selecting single row:
In ultragridgrid InitializeLayout event

e.Layout.Override.SelectTypeRow = Infragistics.Win.UltraWinGrid.SelectType.Single

code for made Fixed Columns
In ultragridgrid InitializeLayout event

e.Layout.UseFixedHeaders = true
UltraGrid.Bands[0].Columns[0].Header.Fixed = true
UltraGrid.Bands[0].Columns[1].Header.Fixed = true
                               OR
Me.UltraGrid.displaylayout.override.AllowCalSizing=AllowCalSizing.None

code for made Fixed Row
Me.UltraGrid.displaylayout.override.RowSizing=RowSizing.Fixed

Change cell button properties/appeacence
In ultragridgrid InitializeLayout event

e.Layout.Bands(0).Columns("name of cell write here").CellButtonAppearance

code for Disable Column Sorting
In ultragridgrid InitializeLayout event


e.Layout.Override.HeaderClickAction = HeaderClickAction.Select
e.Layout.Override.SelectTypeCol = SelectType.None

code to enable immediate scrolling

In ultragridgrid InitializeLayout event

e.Layout.ScrollBounds = ScrollBounds.ScrollToFill
e.Layout.ScrollStyle = ScrollStyle.Immediate


code  for Update datasource for each cell change
In ultragridgrid InitializeLayout event

UltraGrid1.UpdateMode = Infragistics.Win.UltraWinGrid.UpdateMode.OnCellChange

code if you want To change grid Header Appearance

In ultragridgrid InitializeLayout event

UltraGrid1.DisplayLayout.Bands(0).Override.HeaderAppearance property

code if you want To disable column swapping, moving,sizing and GroupBy
In ultragridgrid InitializeLayout event

With UltraGrid1.DisplayLayout.Bands(0).
.Override.AllowColMoving = AllowColMoving.NotAllowed
.Override.AllowColSwapping = AllowColSwapping.NotAllowed
.Override.AllowColSizing = AllowColSizing.None
.Override.AllowGroupBy = DefaultableBoolean.False


code for Show header text in multi line

In ultragridgrid InitializeLayout event


UltraGrid1.DisplayLayout.Bands(0).Override.WrapHeaderText = DefaultableBoolean.False
UltraGrid1.ColHeaderLines = 2 'two lines
UltraGrid1.Columns(0).Header.Caption = "here write text" & Environment.NewLine & "here write text"


code to select a full row if click on any cell
In ultragrid InitializeLayout event

UltraGrid1.DisplayLayout.Bands(0).Override.CellClickAction = CellClickAction.RowSelect

code for Hide a column
In ultragrid InitializeLayout event
UltraGrid1.DisplayLayout.Bands(0).Columns("here write column name").Hidden = True


code for Adding DropDownList column
In ultragrid InitializeLayout event


UltraGrid1.DisplayLayout.Bands(0).Columns("here write ColumnName").Style = ColumnStyle.DropDownList
UltraGrid1.DisplayLayout.Bands(0).Columns("here write ColumnName").ValueList = UltraGrid1.DisplayLayout.ValueLists("my list")

' now create ultragrid list
UltraGrid1.DisplayLayout.ValueLists.Add("my list")
UltraGrid1.DisplayLayout.ValueLists("my list ").ValueListItems

Dim list As New ValueListItem()

list.DataValue = 1
list.DisplayText = "car"
.Add(list)

list= New ValueListItem()
list.DataValue = 2
list.DisplayText = "bus"
.Add(list)

list= New ValueListItem()
list.DataValue = 3
list.DisplayText = "train"
.Add(list)


list= New ValueListItem()
list.DataValue = 4
list.DisplayText = "motor cycle"
.Add(list)



code for Adding a button column
In ultragrid InitializeLayout event

UltraGrid1.DisplayLayout.Bands(0).Columns(0).Style = ColumnStyle.Button
UltraGrid1.DisplayLayout.Bands(0).Columns(0).ButtonDisplayStyle = UltraWinGrid.ButtonDisplayStyle.Always


code for make cell text multi line
In ultragridgrid InitializeLayout event

UltraGrid1.DisplayLayout.Bands(0).Columns(0).CellMultiLine = DefaultableBoolean.True


UltraGrid1.DisplayLayout.Bands(0).Columns(0).VertScrollBar = True

code for reset the sorted columns when unloading
ultraGrid1.DisplayLayout.Bands[0].SortedColumns.Clear()

Do not show Expansion Indicator when there are no child items/band
In grid InitializeLayout event handler, set

UltraGrid1.DisplayLayout.Bands(0).Override.ExpansionIndicator=ShowExpansionIndicator.CheckOnDisplay
'code for increasing the default row height of the ultra grid

UltraGrid1.DisplayLayout.Override.DefaultRowHeight = 500

'code for change column header text
In ultragrid InitializeLayout event

UltraGrid1.DisplayLayout.Bands(0).Columns(0).Header.Caption = "My header"

code for change date column format
In ultragrid InitializeLayout event

UltraGrid1.DisplayLayout.Bands(0).Columns(0).Format = "dd/mm/yyyy hh:mm:ss"


code for Adding an image to a cell
In ultragrid InitializeLayout event
now you Add an image to resource file to access from My.Resources here in the below code
UltraGrid1.DisplayLayout.Bands(0).Columns(0).CellButtonAppearance.Image = My.Resources.img

'img is the name image

'code for make Non Editable column and Editable column

'In ultragrid InitializeLayout event
'for code to allow if u want edit

UltraGrid1.DisplayLayout.Bands(0).Columns(0).CellActivation = Activation.AllowEdit

'code for locking the cell
UltraGrid1.DisplayLayout.Bands(0).Columns(0).CellActivation = Activation.NoEdit

code To add a band header
In ultragrid InitializeLayout event
'for header visibility true
UltraGrid1.DisplayLayout.Bands(0).HeaderVisible = True

' code for gave header name
UltraGrid1.DisplayLayout.Bands(0).Header.Caption = "My Header name is write here "

'code for aligning the header text appearence
UltraGrid1.DisplayLayout.Bands(0).Header.Appearance.TextHAlign = HAlign.right

'there are also other alignment setting in ultragrid


Friday, 24 May 2013

how to add image/icon and text in ultratool control on specific and all tab in vb.net

Hi everyone
that is the way to add image or icon on tab(specific ) and all tab of ultra Tab control

Step 1 :
Add image on your resource file folder on your code
Go on Your Solution Explore  and then go on My Project then click on Resources.resx
image select option then add image
After That
Step 2:
add this code in your Form. i add  image In my resource folder ambulance1_256 please change the name of pics with that
  This line is add for show same pics/icon on all tab

   'Me.UltraTabControl1.Appearance.Image = My.Resources.ambulance1_256
'Here is line for Adding image on tab 1 and tab 3

        Me.UltraTabPageControl1.Tab.Appearance.Image = My.Resources.ambulance1_256
        Me.UltraTabPageControl3.Tab.Appearance.Image = My.Resources.ambulance1_256
'for adding text in specific tab please write that code. i add on the first tab
 Me.UltraTabPageControl1.Tab.Text = "ahmad"
I Hope that code is helpful to you.if you need more help please tell me by comments

Regards:
Ahmad Khalid
Software Engineer




Thursday, 23 May 2013

custom tab control for remove the dashed rectangle around the selected tab when in focus in vb.net

Hi Everyone
When i started work on tab control i have issue of  tabcontrol  it should  draw the focus rectangle on the active tab. Maybe something along the lines of changing the ActiveTabAppearance or something
For the solution there is demo code which i share with you hope that it will be helpful to you

Please Visit The Following Bellow Link

https://skydrive.live.com/?cid=89b1ec9962a06802&id=89B1EC9962A06802%21109&Bsrc=Share&Bpub=SDX.SkyDrive&authkey=!Ai9AMkOpPjAdhVc


Regards:
Ahmad Khalid
Software Engineer

Thursday, 9 May 2013

work on ultra grid


Imports Infragistics.Win
Imports System.Data.SqlClient
Imports Infragistics.Win.UltraWinGrid

Public Class Form1
    Dim adapter As New SqlDataAdapter
    Dim ds As New DataSet
    Dim dr As DataRow
    Dim binding As BindingManagerBase
    Dim dt As DataTable
    Dim connstring As SqlConnection = New SqlConnection(alarm.My.Settings.con)
    Dim band As BandsCollection
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the 'AHMADDataSet.person' table. You can move, or remove it, as needed.
        Me.PersonTableAdapter.Fill(Me.AHMADDataSet.person)

        'dt = New DataTable()
        adapter.SelectCommand = New SqlCommand("SELECT  id ,name,fathername,address,marks,rollno,qualification FROM person", connstring)
        'DataGridView1.DataSource = dt

        'UltraGrid1.DataSource = dt
        'dt.Columns(2).ColumnMapping = MappingType.Hidden
        '...........................................................................................
        adapter.Fill(ds)
        'dt.Columns(1).Caption = "hello hello"
        'adapter.Fill(dt)
        '................................................binding code...................................................
        BindControls()
        binding = BindingContext(ds.Tables(0))
        binding.Position = 0
        UltraGrid1.DataSource = ds.Tables(0)
        '...............................................................................................
        'Me.UltraGrid1.DisplayLayout.AddNewBox.BorderStyle = UIElementBorderStyle.TwoColor
        'Me.UltraGrid1.DisplayLayout.AddNewBox.Appearance.BackColor = Color.Pink
        '..........................................................................
        'background color of grid you set in this way
        Me.UltraGrid1.DisplayLayout.Appearance.BackColor = Color.Gold
        '..............................................................................
        'Dim col As UltraGridColumn
        'For Each col In Me.UltraGrid1.DisplayLayout.Bands(0).Columns


        '    col.Header.Appearance.BackColor = Color.Purple

        '    '    ' Here we "turn off" theming for the column header.
        '    'col.Header.Appearance.ThemedElementAlpha = Infragistics.Win.Alpha.Transparent


        '    'col.Header.Appearance.BackColorDisabled = Color.PaleGreen
        'Next
        '.................NAME OF HEADER OF ULTRA GRID and set the specfic header color change..........................
        'Me.UltraGrid1.Text = "Test Grid"
        'Me.UltraGrid1.DisplayLayout.Bands(0).Columns("name").Header.Appearance.BackColor = Color.LightGoldenrodYellow
        ''.......................................
' header position are cahnge in this way
 Me.UltraGrid1.DisplayLayout.Bands(0).Columns("fathername").Header.VisiblePosition = 4
        ''.................set the specfic coloumn color change...........................................
        'Me.UltraGrid1.Rows(3).Cells(2).Appearance.BackColor = Color.Orange
        ''..........................set the specfic active coloumn color change...........................
        'Me.UltraGrid1.Rows(3).Cells(3).ActiveAppearance.BackColor = Color.Silver
        '//////////////////////////////////////////////////////////////////////////
        'Me.UltraGrid1.Rows(3).Cells(1).SelectedAppearance.BackColor = Color.Violet
        Me.UltraGrid1.DisplayLayout.Bands(0).Override.AllowDelete = DefaultableBoolean.False
        'Me.UltraGrid1.DisplayLayout.Bands(0).Columns(0).CellActivation = Activation.Disabled
        'Me.UltraGrid1.DisplayLayout.Bands(0).Columns(1).CellActivation = Activation.Disabled
        'Me.UltraGrid1.DisplayLayout.Bands(0).Columns(2).CellActivation = Activation.Disabled
        'Me.UltraGrid1.DisplayLayout.Bands(0).Columns(3).CellActivation = Activation.Disabled
        'Me.UltraGrid1.DisplayLayout.Bands(0).Columns(4).CellActivation = Activation.Disabled
        'Me.UltraGrid1.DisplayLayout.Bands(0).Columns(5).CellActivation = Activation.Disabled
        'Me.UltraGrid1.DisplayLayout.Bands(0).Columns(6).CellActivation = Activation.Disabled
        '//////////////////////////////////////// remove default selection of first row/////////////////////////////////
        UltraGrid1.DisplayLayout.Override.ActiveCellAppearance.Reset()
        UltraGrid1.DisplayLayout.Override.ActiveRowAppearance.Reset()
        '/////////////ADD BANDS IN ULTRAGRID CODE IS HERE//////////////////////////////////////////
        Me.UltraGrid1.DisplayLayout.ViewStyleBand = ViewStyleBand.OutlookGroupBy
        'Me.UltraGrid1.DisplayLayout.Bands(0).SortedColumns.Add("name", False, True)
        Me.UltraGrid1.DisplayLayout.Bands(0).SortedColumns.Add("fathername", False, True)
        Me.UltraGrid1.Rows.ExpandAll(True)
        '////////////////////CODE FOR ADD BANDS IN ULTRAGRID CODE IS END HERE/////////////////////////////////////////
     
    End Sub
    Private Sub BindControls()
        UltraTextEditor1.DataBindings.Add("Text", ds.Tables(0), "id")
        UltraTextEditor2.DataBindings.Add("Text", ds.Tables(0), "name")
        UltraTextEditor3.DataBindings.Add("Text", ds.Tables(0), "fathername")
        UltraTextEditor4.DataBindings.Add("text", ds.Tables(0), "address")
        UltraTextEditor5.DataBindings.Add("text", ds.Tables(0), "marks")
        UltraTextEditor6.DataBindings.Add("Text", ds.Tables(0), "rollno")
        UltraTextEditor7.DataBindings.Add("Text", ds.Tables(0), "qualification")

    End Sub

    Private Sub UltraButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles UltraButton1.Click
        adapter.InsertCommand = New SqlCommand("INSERT INTO person (name,fathername,address,marks,rollno,qualification) " & "VALUES (@name,@fathername,@address,@marks,@rollno,@qualification)", connstring)
        adapter.InsertCommand.Parameters.Add("@name", SqlDbType.NVarChar, 15, "name")
        adapter.InsertCommand.Parameters.Add("@fathername", SqlDbType.NVarChar, 15, "fathername")

        adapter.InsertCommand.Parameters.Add("@address", SqlDbType.NVarChar, 100, "address")
        adapter.InsertCommand.Parameters.Add("@marks", SqlDbType.Int, 15, "marks")
        adapter.InsertCommand.Parameters.Add("@rollno", SqlDbType.Int, 15, "rollno")
        adapter.InsertCommand.Parameters.Add("@qualification", SqlDbType.NVarChar, 100, "qualification")


        adapter.UpdateCommand = New SqlCommand("UPDATE person SET name=@name,fathername=@fathername,address=@address,marks=@marks,rollno=@rollno,qualification=@qualification " & "WHERE id = @id", connstring)
        adapter.UpdateCommand.Parameters.Add("@id", SqlDbType.Int, 15, "id")
        adapter.UpdateCommand.Parameters.Add("@name", SqlDbType.NVarChar, 15, "name")
        adapter.UpdateCommand.Parameters.Add("@fathername", SqlDbType.NVarChar, 15, "fathername")
        adapter.UpdateCommand.Parameters.Add("@address", SqlDbType.NVarChar, 100, "address")

        adapter.UpdateCommand.Parameters.Add("@marks", SqlDbType.Int, 15, "marks")
        adapter.UpdateCommand.Parameters.Add("@rollno", SqlDbType.Int, 15, "rollno")
        adapter.UpdateCommand.Parameters.Add("@qualification", SqlDbType.NVarChar, 100, "qualification")

        adapter.DeleteCommand = New SqlCommand("DELETE FROM person WHERE id = @id", connstring)
        adapter.DeleteCommand.Parameters.Add("@id", SqlDbType.Int, 15, "id")
        adapter.Update(ds)
    End Sub

    Private Sub UltraButton2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles UltraButton2.Click
        '/////////FOR GO ON THE FIRST RECORD  CODE START HERE//////////////////////////////////////////
        UltraGrid1.Rows(0).Selected = True
        binding.Position = 0
        '//////////FOR GO ON THE FIRST RECORD  CODE END HERE //////////////////////
    End Sub

    Private Sub UltraButton3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles UltraButton3.Click
        '/////////FOR GO ON THE LAST RECORD  CODE START HERE//////////////////////////////////////////
        UltraGrid1.Rows(0).Selected = True

        binding.Position = binding.Count - 1
        '/////////FOR GO ON THE LAST RECORD  CODE END HERE//////////////////////////////
    End Sub

    Private Sub UltraButton5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles UltraButton5.Click
        '////////FOR GO ON THE PREVIOUS RECORD  CODE START HERE///////////////////
        binding.Position = binding.Position - 1
        '//////////////FOR  GO ON THE PREVIOUS RECORD  CODE END HERE///////////////////////
    End Sub

    Private Sub UltraButton4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles UltraButton4.Click
        '////////FOR GO ON THE NEXT RECORD  CODE START HERE///////////////////
        binding.Position = binding.Position + 1
        '////////FOR GO ON THE NEXT RECORD  CODE END HERE///////////////////
    End Sub

    Private Sub UltraButton6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles UltraButton6.Click
        ' //////// FOR ADD NEW RECORD/ OR ADD NEW ROW HERE CODE START HERE///////////////
        Dim dr As DataRow = ds.Tables(0).NewRow()
        ds.Tables(0).Rows.Add(dr)
        binding.Position = binding.Count - 1
        ' //////// FOR ADD NEW RECORD/ OR ADD NEW ROW HERE CODE END HERE///////////////
    End Sub
    'set the color of selected rows..........................................................................................
    Private Sub UltraGrid1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles UltraGrid1.Click
        '///////FOR CHANGE THE COLOR OF DEFAULT BLUE COLOR OF SELECTED ROW   CODE START HERE///////
        Me.UltraGrid1.DisplayLayout.Override.ActiveRowAppearance.BackColor = Color.Green
        '//////FOR CHANGE THE COLOR OF DEFAULT BLUE COLOR OF SELECTED ROW   CODE END HERE
    End Sub

    Private Sub UltraGrid1_ClickCell(ByVal sender As Object, ByVal e As Infragistics.Win.UltraWinGrid.ClickCellEventArgs) Handles UltraGrid1.ClickCell
        'Me.UltraGrid1.Rows(3).Cells(1).SelectedAppearance.BackColor = Color.Violet

    End Sub

    Private Sub UltraGrid1_InitializeLayout(ByVal sender As Object, ByVal e As Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs) Handles UltraGrid1.InitializeLayout
        '////////FOR ADD VALUE LIST CODE IS START HERE//////////////////////////////////
        Dim vl As ValueList

        If (Not e.Layout.ValueLists.Exists("MyValueList")) Then
            vl = e.Layout.ValueLists.Add("MyValueList")
            vl.ValueListItems.Add("AHMAD", "AHMAD")
            vl.ValueListItems.Add("WASIM", "WASIM")
            vl.ValueListItems.Add("RASHID", "RASHID")
            vl.ValueListItems.Add("Misbah", "Misbah")
            vl.ValueListItems.Add("HANAN", "HANAN")
            vl.ValueListItems.Add("huma", "huma")
            vl.ValueListItems.Add("rahil", "rahil")
            vl.ValueListItems.Add("RAHUL", "RAHUL")
            vl.ValueListItems.Add("USMAN", "USMAN")
            vl.ValueListItems.Add("WALID", "WALID")
            vl.ValueListItems.Add("JAVED", "JAVED")
            vl.ValueListItems.Add("CYRUS", "CYRUS")
            vl.ValueListItems.Add("ZAIGUM", "ZAIGUM")
            vl.ValueListItems.Add("AMNA", "AMNA")
            vl.ValueListItems.Add("HIRA", "HIRA")
            vl.ValueListItems.Add("NASIR", "NASIR")
            vl.ValueListItems.Add("FAROOQ", "FAROOQ")
            vl.ValueListItems.Add("NAYYARA", "NAYYARA")
            vl.ValueListItems.Add("AZAM", "AZAM")
            vl.ValueListItems.Add("ALVI", "ALVI")
            vl.ValueListItems.Add("CYRUS", "CYRUS")
            vl.ValueListItems.Add("ZAIGUM", "ZAIGUM")
            vl.ValueListItems.Add("Saood", "Saood")
            vl.ValueListItems.Add("Fatima", "Fatima")
            vl.ValueListItems.Add("Khalid", "Khalid")
            vl.ValueListItems.Add("Hassan", "Hassan")
            vl.ValueListItems.Add("Raza", "Raza")
            vl.ValueListItems.Add("ANUM", "ANUM")
            vl.ValueListItems.Add("Moosa", "Moosa")
            vl.ValueListItems.Add("fahad", "fahad")
            vl.ValueListItems.Add("naheed", "naheed")
            vl.ValueListItems.Add("Iram", "Iram")
            vl.ValueListItems.Add("RABIYYA", "RABIYYA")
            vl.ValueListItems.Add("WAQAS", "WAQAS")
            vl.ValueListItems.Add("ASHRAF", "ASHRAF")
            vl.ValueListItems.Add("AMIR", "AMIR")

        End If

        e.Layout.Bands(0).Columns("name").ValueList = e.Layout.ValueLists("MyValueList")
        '//////////////////FOR ADD VALUE LIST CODE IS END HERE
        e.Layout.Bands(0).Columns(1).CellActivation = Infragistics.Win.UltraWinGrid.Activation.ActivateOnly
        e.Layout.Bands(0).Columns(1).CellAppearance.ForeColor = Color.Blue
        e.Layout.Bands(0).Columns(1).CellAppearance.FontData.Underline = Infragistics.Win.DefaultableBoolean.True
        e.Layout.Bands(0).Columns(1).CellAppearance.Cursor = Cursors.Hand
     
     
    End Sub

    '................................................................................................................................

    Private Sub UltraGrid1_InitializeRow(ByVal sender As Object, ByVal e As Infragistics.Win.UltraWinGrid.InitializeRowEventArgs) Handles UltraGrid1.InitializeRow
        '//////////////////////////////Set the background color of ultragrid/////////////////////////////////////.........................
        e.Row.Appearance.BackColor = Color.Brown
        '.................................................................................................................................
        '/////////////////////////////set the fore color of ultragrid////////////////////////////////////////////.........................
        e.Row.Appearance.ForeColor = Color.HotPink
        '......................................................................
        '...............................hide the id coloumn...................................................
        'UltraGrid1.DisplayLayout.Bands(0).Columns(0).Hidden = True
        Me.UltraGrid1.DisplayLayout.Bands(0).Columns(0).SortIndicator = SortIndicator.Descending

        e.Row.ExpandAll()
        '////////////////// part for add hyperlink in ultragrid///////////////////enter coloumn name for serach here 2=fathername and in  e.Row.Cells(1)=where the location of hyperlink here name=1
        e.Row.Cells(1).Tag = "http://www.google.com/search?hl=en&q=" + e.Row.Cells(2).Value.ToString.Replace(" ", "+")
        '///////////////part for add hyperlink in ultragrid///////////////


        Me.UltraGrid1.DisplayLayout.Bands(0).Columns("name").Style = ColumnStyle.Button
        Dim row As UltraGridRow
        For Each row In Me.UltraGrid1.Rows
            'row.ToolTipText = String.Format("Sample tool tip for {0} index row.", row.Index)

            ' Tool tip can be set on individual cells as well.

            row.Cells(0).ToolTipText = String.Format("coloumn id  for {0} index row.", row.Index)
            row.Cells(1).ToolTipText = String.Format("coloumn name  for {0} index row.", row.Index)
            row.Cells(2).ToolTipText = String.Format("coloumn fathername  for {0} index row.", row.Index)
            row.Cells(3).ToolTipText = String.Format("coloumn address  for {0} index row.", row.Index)
            row.Cells(4).ToolTipText = String.Format("coloumn marks  for {0} index row.", row.Index)
            row.Cells(5).ToolTipText = String.Format("coloumn rollno  for {0} index row.", row.Index)
            row.Cells(6).ToolTipText = String.Format("coloumn qualification  for {0} index row.", row.Index)
        Next
    End Sub
 
 
    Private Sub UltraButton7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles UltraButton7.Click
        Dim index As Integer

        Try
            connstring.Open()

            Dim myQyery As String = "SELECT * FROM [person] WHERE ([name] = '" + UltraTextEditor8.Text + "')"
            adapter = New SqlDataAdapter(myQyery, connstring)
            Dim dt As New DataTable
            adapter.Fill(dt)
            If dt.Rows.Count <= 0 Then
                ' MsgBox("This name Does Not Exist", MsgBoxStyle.DefaultButton1, "Not Exist")
                MsgBox("WARNING! This name Does Not Exist please enter the correct name")

            Else
                UltraGrid1.DataSource = dt
                index = UltraGrid1.ActiveRow.Index
                UltraTextEditor1.Text = dt.Rows()(1).ToString
                UltraTextEditor2.Text = dt.Rows(index)(2).ToString
                UltraTextEditor3.Text = dt.Rows(index)(3).ToString
                UltraTextEditor4.Text = dt.Rows(index)(4).ToString
                UltraTextEditor5.Text = dt.Rows(index)(5).ToString
                UltraTextEditor6.Text = dt.Rows(index)(6).ToString
                UltraTextEditor7.Text = dt.Rows(index)(7).ToString
            End If
        Catch ex As Exception
            MsgBox("you name is MET suceessfully")
        Finally
            connstring.Close()
        End Try
    End Sub

    Private Sub UltraButton8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles UltraButton8.Click

        'If Me.UltraGrid1.Selected.Rows.Count > 0 Then
        '     ' Delete the selected rows by calling DeleteSelectedRows.
        '     Me.UltraGrid1.DeleteSelectedRows()
        ' Else
        '     ' Show a message if there are no selected rows.
        '     MessageBox.Show("There are no rows selected. Select rows first.")
        ' End If
        'Me.UltraGrid1.Selected.Rows.Clear()
        'Me.UltraTextEditor1.Text = "*cleared*"
        'UltraGrid1.DeleteSelectedRows(True)
        '////////DELETE BUTTON CODE SELECTED ROW START HERE///////////
        Dim row As UltraGridRow
        For Each row In Me.UltraGrid1.Selected.Rows


            row.Delete(False)
            Me.UltraGrid1.UpdateData()
        Next
        '////////DELETE BUTTON CODE SELECTED ROW END HERE///////////
    End Sub

    Private Sub UltraGrid1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles UltraGrid1.KeyPress

    End Sub
    '////////////////// hyper link code is there and some part is above////////////////
   Private Sub UltraGrid1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles UltraGrid1.MouseDown
        Dim objClickedElement As UIElement = Me.UltraGrid1.DisplayLayout.UIElement.ElementFromPoint(UltraGrid1.PointToClient(Form1.MousePosition))

        If objClickedElement Is Nothing Then Return

        Dim objCellElement As CellUIElement = objClickedElement.GetAncestor(GetType(Infragistics.Win.UltraWinGrid.CellUIElement))

        If objCellElement Is Nothing Then Return

        Dim objCell As UltraGridCell = CType(objCellElement.GetContext(GetType(UltraGridCell)), UltraGridCell)

        If objCell Is Nothing Then Return
        '/////////////name here as key/////////////
        If objCell.Column.Key = "name" Then
            System.Diagnostics.Process.Start(objCell.Tag.ToString)
        End If
        '/////hyper link code is there and some part is above is end there//////////
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        'UltraGrid1.Rows.Refresh(Infragistics.Win.UltraWinGrid.RefreshRow.ReloadData)
        UltraGrid1.Rows.Refresh(Infragistics.Win.UltraWinGrid.RefreshRow.RefreshDisplay)
    End Sub
 
    Private Sub Display_ToolTips_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ' Set tool tip on a  header column.
        Me.UltraGrid1.DisplayLayout.Bands(0).Columns("id").Header.ToolTipText = "field contain user id ."
        Me.UltraGrid1.DisplayLayout.Bands(0).Columns("name").Header.ToolTipText = "field contains user name ."
        Me.UltraGrid1.DisplayLayout.Bands(0).Columns("fathername").Header.ToolTipText = " field contains user fathername ."
        Me.UltraGrid1.DisplayLayout.Bands(0).Columns("address").Header.ToolTipText = "field contains user address."
        Me.UltraGrid1.DisplayLayout.Bands(0).Columns("marks").Header.ToolTipText = "field contains user marks ."
        Me.UltraGrid1.DisplayLayout.Bands(0).Columns("rollno").Header.ToolTipText = "field contains user rollno ."
        Me.UltraGrid1.DisplayLayout.Bands(0).Columns("qualification").Header.ToolTipText = "field contains user qualification "
        ' Set tool tip on a row.
        'Me.UltraGrid1.Rows(0).Cells(1) = "This is a row tool tip."

        ' Set tool tip on a cell.
        'Me.UltraGrid1.Rows(0).Cells(1).ToolTipText = "This is a cell tool tip."

        ' Add a summary.
        Dim summary As SummarySettings = _
          Me.UltraGrid1.DisplayLayout.Bands(0).Summaries.Add("count", _
          SummaryType.Count, _
          Me.UltraGrid1.DisplayLayout.Bands(0).Columns(0), _
          SummaryPosition.UseSummaryPositionColumn)

        ' Set the tooltip on the summary settings object. This tool tip will
        ' be displayed on every summary value instance associated with this
        ' summary settings object.
        summary.ToolTipText = String.Format("Count of column {0}.", summary.SourceColumn.Header.Caption)

        ' Tooltip can be set on individual summary value objects as well, in case  you
        ' want to display a different tool tip based on the calculated value. A good place
        ' to set such summary value specific tool tips is in SummaryValueChanged event.
        Me.UltraGrid1.Rows.SummaryValues("count").ToolTipText = _
          String.Format("Count of column {0}.", summary.SourceColumn.Header.Caption)
     
    End Sub
End Class

Tuesday, 16 April 2013

How to insert update select and delete data into datagridview through textboxes in vb.net

Aslam O Alaikum!

My todays topic of discussion is "How to insert update select and delete data into datagridview  through textboxes in vb.net".

first i have 2 form i n one form we have only one grid and one button 
and in the second form we have 7 text box field and we have 4 button
here i used databinding and binding manager concept
in above that is the pics of grid view


form1


Imports System.Windows.Forms

Imports System.Data.SqlClient
Imports System.Data.DataRow
Public Class Form1
    Dim adapter As SqlDataAdapter
    Dim ds As DataSet
    Dim connstring As SqlConnection
    Dim bmb As BindingManagerBase


    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        adapter.MissingSchemaAction = MissingSchemaAction.AddWithKey
        adapter.InsertCommand = New SqlCommand("INSERT INTO person ( id,name,fathername,address,marks,rollno,qualification) " & "VALUES (@id,@name,@fathername,@address,@marks,@rollno,@qualification)", connstring)
        adapter.InsertCommand.Parameters.Add("@id", SqlDbType.Int, 15, "id")
        adapter.InsertCommand.Parameters.Add("@name", SqlDbType.NVarChar, 15, "name")
        adapter.InsertCommand.Parameters.Add("@fathername", SqlDbType.NVarChar, 100, "fathername")
        adapter.InsertCommand.Parameters.Add("@address", SqlDbType.NVarChar, 100, "address")
        adapter.InsertCommand.Parameters.Add("@marks", SqlDbType.Int, 15, "marks")
        adapter.InsertCommand.Parameters.Add("@rollno", SqlDbType.Int, 15, "rollno")
        adapter.InsertCommand.Parameters.Add("@qualification", SqlDbType.NVarChar, 100, "qualification")
    

        adapter.UpdateCommand = New SqlCommand("UPDATE person SET id = @id,name=@name,fathername=@fathername,address=@address,marks=@marks,rollno=@rollno,qualification=@qualification " & "WHERE id = @id", connstring)

        adapter.UpdateCommand.Parameters.Add("@id", SqlDbType.Int, 15, "id")
        adapter.UpdateCommand.Parameters.Add("@name", SqlDbType.NVarChar, 15, "name")
        adapter.UpdateCommand.Parameters.Add("@fathername", SqlDbType.NVarChar, 100, "fathername")
        adapter.UpdateCommand.Parameters.Add("@address", SqlDbType.NVarChar, 100, "address")
        adapter.UpdateCommand.Parameters.Add("@marks", SqlDbType.Int, 15, "marks")
        adapter.UpdateCommand.Parameters.Add("@rollno", SqlDbType.Int, 15, "rollno")
        adapter.UpdateCommand.Parameters.Add("@qualification", SqlDbType.NVarChar, 100, "qualification")

        adapter.DeleteCommand = New SqlCommand("DELETE FROM person WHERE id = @id", connstring)

        adapter.DeleteCommand.Parameters.Add("@id", SqlDbType.Int, 15, "id")
        
        adapter.Update(ds)
    End Sub

    

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.PersonTableAdapter.Fill(Me.AhmadDataSet.person)
        adapter = New SqlDataAdapter
        ds = New DataSet
        connstring = New SqlConnection(checking.My.Settings.constring)
        adapter.SelectCommand = New SqlCommand("SELECT id, name,fathername,address,marks,rollno,qualification FROM person", connstring)
        adapter.Fill(ds)
        
        DataGridView1.DataSource = ds.Tables(0)
        ' DataGridView1.Columns(0).Visible = False
        'DataGridView1.Columns(1).ReadOnly = True
        ' DataGridView1.Columns(2).ReadOnly = True
        ' DataGridView1.Columns(3).ReadOnly = True
        Button1.Hide()
    End Sub
    'Private Sub BindControls()

    'End Sub


   

  
   
    Private Sub DataGridView1_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick

    End Sub


    Private Sub DataGridView1_CellDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellDoubleClick

        Form2.Show()
        Me.Hide()
    End Sub
End Class

form2



Imports System.Windows.Forms
Imports System.Data.SqlClient
Imports System.Data.DataRow


Public Class Form2

    Dim adapter As SqlDataAdapter
    Dim ds As DataSet
    Dim connstring As SqlConnection
    Dim bmb As BindingManagerBase




    Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load


        Form1.PersonTableAdapter.Fill(Form1.AhmadDataSet.person)

        adapter = New SqlDataAdapter
        ds = New DataSet
        connstring = New SqlConnection(checking.My.Settings.constring)
        adapter.SelectCommand = New SqlCommand("SELECT id, name,fathername,address,marks,rollno,qualification FROM person", connstring)
        adapter.Fill(ds)
        BindControls()
        bmb = BindingContext(ds.Tables(0))
        bmb.Position = 0
        Form1.DataGridView1.DataSource = ds.Tables(0)
    End Sub
    Private Sub BindControls()
        TextBox1.DataBindings.Add("Text", ds.Tables(0), "id")
        TextBox2.DataBindings.Add("Text", ds.Tables(0), "name")
        TextBox3.DataBindings.Add("text", ds.Tables(0), "fathername")
        TextBox4.DataBindings.Add("text", ds.Tables(0), "address")
        TextBox5.DataBindings.Add("Text", ds.Tables(0), "marks")
        TextBox6.DataBindings.Add("Text", ds.Tables(0), "rollno")
        TextBox7.DataBindings.Add("text", ds.Tables(0), "qualification")

    End Sub


   

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        bmb.Position = bmb.Position + 1
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

        bmb.Position = bmb.Position - 1
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click

        Dim dr As DataRow = ds.Tables(0).NewRow()
        ds.Tables(0).Rows.Add(dr)
        bmb.Position = bmb.Count - 1
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click

        Form1.Show()
        Me.Hide()
    End Sub
End Class

i hope you will be understand my that work and it will be helpfull to u


ALLAH blessed me and all the readers. Keep remember me in your prayers.