Can I Enter values into Data Grid View manually- Urgent Help

Hi,

I am developing a vb.net windows forms application.
I have a data grid view in this application, I am retreiving data into the data grid view using ado.net.
I added an extra column manually using code below:
Please help me the issues I have:
1.I am able to get the column in my data grid view, but it empty, I can understand that I haven't passed any data to the column so it is displaying empty(since this column is not from the database), what should I do inorder to set the default value in the column for all the rows as Zero '0'.
2.How can I restrict the user from entering characters, I want the user to enter only numeric values.
3.When I click a button all the values in all the rows of this column should change from '0'  to  '1'.
4.Is they any option to refresh the windows form for every 30 seconds.

I also have attached the data grid view ouput, where I have got the extra column without any data since it is not from the database.


If GetDataSet(DS, sSQL) Then
            With DS.Tables("Table")
                count = .Rows.Count
                If .Rows.Count > 0 Then
                    dt = DS.Tables("Table")
                    RDGVW.DataSource = dt
                    RDGVW.Columns.Add(num, "NUMBERS")
                End If
            End With
        End If

Open in new window

code.doc
LVL 1
SGUDAPATAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

carlsiyCommented:
answers...
for
#1
 you can add the statement in your select query such as.. "select .... , 0 as columnname from  ....."  the returning query would have a column with 0 values.
#2
you have to manually make a datatable, normally datatable's are just passed from sql query output. but you can also modify the datatable structure and component, what you need here is to inherit the NumericUpDown object within a column of the datatable.
#3
This can be done through looping through all the row of the datatable to change the cell value of a specific column.
#4
Yes, there is put the refresh option within a timer object.
0
SGUDAPATAuthor Commented:
Hi Carlsiy,

 #1:Do you mean to say that I should write the select query for the data table which is created manually?
#2:I am a beginner into VB.Net, could please tell me how I can create datatable manually.
#4:Does Vb.Net have any in-built timer objects which can be used or do I need to create a timer object.
0
carlsiyCommented:
for
#1
you can use e.g. "Select field1, field2, 0 as field3 from sample_table " 
the return here would be
field1     field2     field3    
<data>  <data>    0
<data>  <data>    0
<data>  <data>    0

#2
heres a quick sample (creation of data table and its columns)

  Dim myDataTable As DataTable = New DataTable()

  Dim myDataColumn As DataColumn

  myDataColumn = New DataColumn()
  myDataColumn.DataType = Type.GetType("System.String")
  myDataColumn.ColumnName = "id"
  myDataTable.Columns.Add(  myDataColumn)

  myDataColumn = New DataColumn()
  myDataColumn.DataType = Type.GetType("System.String")
  myDataColumn.ColumnName = "username"
  myDataTable.Columns.Add(  myDataColumn)

  myDataColumn = New DataColumn()
  myDataColumn.DataType = Type.GetType("System.String")
  myDataColumn.ColumnName = "firstname"
  myDataTable.Columns.Add(  myDataColumn)

  myDataColumn = New DataColumn()
  myDataColumn.DataType = Type.GetType("System.String")
  myDataColumn.ColumnName = "lastname"
  myDataTable.Columns.Add(  myDataColumn)


#4
yes there is its called the Timer Object.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

SGUDAPATAuthor Commented:
Hi Carlsiy,

I am little confused about the data table, in my application I created a data table like the code below and passed it to the data grid view, to populate the data grid view, and I have added an extra column manually, can you explain me once again what I should do inoder to set the default value of the extra column which which I manually created to '0'.
 Dim dt As New DataTable
        Dim DS As New DataSet
        'Select the data from the table and sets it to the dataset
        sSQL = "SELECT RECEIVER_ID AS RECEIVER_NO, RECV_LN_NBR AS      
                LINE_NO, INV_ITEM_ID AS ITEM_ID " & _
              "FROM PS_THI_RECV_PRINT WHERE PRINT_BAR_CODE = 'N' ORDER BY LINE_NO"
        If GetDataSet(DS, sSQL) Then
            With DS.Tables("Table")
                count = .Rows.Count
                If .Rows.Count > 0 Then
                    dt = DS.Tables("Table")
                    RecevierDGVW.DataSource = dt
                    With RecevierDGVW.Columns
                        .Add(numLbl, "NUM. OF LABELS")
                    End With
                End If
            End With
        End If
    End Sub

Open in new window

0
carlsiyCommented:
The stlye of datatable creation that you are using is automatic, which means that the columns and constraints of the datatable depends on the return of your query, based on the original datasource. so e.g. if receiver_no in your database is text the datacolumn created in the datatable is data typed string.

if you are to manually add it like this
  myDataColumn = New DataColumn()
  myDataColumn.DataType = Type.GetType("System.Double") 'Declared the datatype
  myDataColumn.ColumnName = "receiver_no"
  myDataTable.Columns.Add(  myDataColumn)

opposed to this
                    With RecevierDGVW.Columns
                        .Add(numLbl, "NUM. OF LABELS")
                    End With
which you just added a textbox column to your datagrid view

The more controlled flow would be... SQL Query --> DataTable or DataSet --> DatagridView

SQL Query => Defines the source of data
DataTable or DataSet => Defines the column length, DataType etc...
DataGridView => Defines the U.I. for the DataTable or DataSet output (normally its a textbox, but can be changed into a NumericUpDown object to fit your needs.)


0
carlsiyCommented:
But for your purpose...
     
  For i As Integer = 0 To RecevierDGVW.Rows.Count
            RecevierDGVW("<column_Name>", i).Value = 0
  Next

this should fix it... but only for the Datagridview not tha datatable.
0
SGUDAPATAuthor Commented:
Hi Carlsiy,
Thanks for the solution.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.