default a value in a datagridview

rjhe22

Well-known member
Joined
May 22, 2008
Messages
88
Programming Experience
Beginner
hi all
i have this bit of code and i want the contactrole part while is a combo box to default to one of the items u can pick in the combo box. how can this be done

Code:


Dim dlg As New dlgSettings("BankContact", "BankID")
dlg.GridMain.Columns("EntityID").Visible = False
dlg.GridMain.Columns("FullName").Visible = False
dlg.Lookup("ContactRoleID", "ContactRole", "ContactRole")
dlg.GridMain.Columns("PhoneNumber").HeaderText = "Fax Number"
dlg.ColumnDefaultValue("Isdefault", True)
dlg.WindowState = FormWindowState.Maximized
dlg.ShowDialog()
dlg.Dispose()
 
Set the default value of the underlying datatable column, not the grid. The grid just shows data, it has nothing to do with storing or creating it
 
VB.NET:
With MyDataSet.MyDataTable("TableName")
     .Columns("SomeDateColumn").DefaultValue = Date.Today
     .Columns("SomeQuantityColumn").DefaultValue = 1
End With
 
how come something like this would not work

dlg.ColumnDefaultValue("Conversion") = 2 or something along those lines
 
Re-read CJ's post.

Your datagridview is not holding the data only displaying it from another object. Somewhere else you are storing this data (dataset, datatable, datarows etc) this is where you want to control & format your values.

To be of more help you should post how the data is being retrieved.
 
i think this will work
With MyDataSet.MyDataTable("TableName")
.Columns("SomeDateColumn").DefaultValue = Date.Today
.Columns("SomeQuantityColumn").DefaultValue = 1
End With

just dont no how to change it around to suit me. i will have another go at it
 
Neither do we, because we don't know what you called your DataSet/DataTable.. Only you know that
 
VB.NET:
#Region " Class Options                 "
Option Explicit On
Option Strict On
#End Region
#Region " Imports                       "
Imports CIMAUtillity
Imports CIMALock
#End Region
Public Class frmBankConsole
#Region " Properties                    "
    Private _data As clsDataCIMABank
    Private _log As DataTable


#End Region
#Region " Initialize and Dispose        "

    Public Sub New()

        ' This call is required by the Windows Form Designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.
        Try
            Me._data = New clsDataCIMABank
            Me._data.Connect("Harvest")
            Me._data.ShowError = False
        Catch ex As Exception
            MessageBox.Show("System May be off-line" & vbCrLf & "Try Again Later", "Startup Error", MessageBoxButtons.OK, MessageBoxIcon.Stop)
            Environment.Exit(0)
        End Try
        Me.initiLog()
    End Sub
#End Region

#Region " Private Support               "

    Private Sub initiLog()
        Me._log = New DataTable("Log")
        With Me._log.Columns
            .Add(New DataColumn("Process", Type.GetType("System.String")))
            .Add(New DataColumn("StartTime", Type.GetType("System.DateTime")))
        End With
        Me.grdMain.DataSource = Me._log
        Me.grdMain.Columns("Process").AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill
    End Sub

    Private Sub status(ByVal Message As String)
        Me.tslStatus.Text = Message
        Dim rowN As DataRow = Me._log.NewRow
        rowN.Item("Process") = Message
        rowN.Item("StartTime") = DateTime.Now
        Me._log.Rows.Add(rowN)
        rowN = Nothing
        Me.stsMain.Refresh()
        Me.grdMain.Refresh()
    End Sub

this is the code from the start of the page
 
According to that example your datatable name is _log. To set a default value for it

_log.Columns("NameOfYourColumnHere").DefaultValue = "TheDefaultValueYouWant"
 

Latest posts

Back
Top