473,382 Members | 1,752 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

datagrid Add

Hi All

I am trying to (with a button click) add a new row to a datagrid and then
set focus on the first column of the new row. I have waisted almost a day
on this now and still can't get it to work. Any help would be greatly
appreciated.

Here is some code

Private Sub btnAdd_Click(ByVal sender As System.Object, _

ByVal e As System.EventArgs) Handles btnAdd.Click

Dim nrecords As Integer = ds.Tables(0).Rows.Count

addRecord()

'Here I need to set focus on the new cell in the datagrid.

End Sub

Protected Overridable Sub addRecord()

ds.Tables(0).DefaultView.AllowNew = True

bNewRow = True

bmb.AddNew()

bmb.Position = bmb.Count - 1

ds.Tables(0).DefaultView.AllowNew = False

Me.SetButtons(1)

End Sub

Thanks

Randy


Nov 20 '05 #1
2 1055
Hi Randy,

Normaly you have only to do this when that dataset is the datasource of your
datagrid and than it is the last row.

ds.Tables(0).rows.add(ds.tables(0).newrow)
DataGrid1.Select(ds.tables(0).Rows.Count - 1)
DataGrid1.CurrentRowIndex = ds.tables(0).Rows.Count - 1

However show us what is your datasource because when it is the dataview with
a sort in it, it is of course not this.

I hope this helps already a little bit.

Cor
Nov 20 '05 #2
I think the problem might be because I am using a Minding manager bound to a
comboBox and the datagrid. Maybe this is not the proper way of doing this.

It seems to work OK in every other aspect other than adding new records. I
tried your code and it worked better but only would select the current row.
I would like to go one step further and select the textbox in the first
column of the grid. The cboSearch Box will not clear even if I tell it that
its text = "" and/or its selectedIndex = -1. I think I am going to have to
loose that binding.

Here is my bind method:

Private Sub Bind()

Dim i As Integer

Dim lst As New DataTable

bmb = Me.BindingContext.Item(ds.Tables("ItemLocations"))

MyBase.DisplayPosition()

grdCatalog.ReadOnly = False

grdCatalog.TabStop = True

'Attach dataset's DefaultView to the datagrid control

'grdCatalog.DataSource = ds.Tables("ItemLocations").DefaultView

'no adding of new rows thru dataview...

lst = ds.Tables("ItemLocations")

grdCatalog.DataSource = ds.Tables("ItemLocations")

With cboSearch

..DataSource = ds.Tables("ItemLocations")

..DisplayMember = "LocationID"

..ValueMember = "LocationID"

..SelectedIndex = -1

..SelectedIndex = -1

End With

MyBase.bLoading = False

If ds.Tables(0).Rows.Count = 0 Then

MyBase.SetButtons(6) 'Empty dataset

Else

MyBase.SetButtons(0)

End If

bnewRow = False

End Sub
"Cor Ligthert" <no**********@planet.nl> wrote in message
news:eX**************@TK2MSFTNGP10.phx.gbl...
Hi Randy,

Normaly you have only to do this when that dataset is the datasource of your datagrid and than it is the last row.

ds.Tables(0).rows.add(ds.tables(0).newrow)
DataGrid1.Select(ds.tables(0).Rows.Count - 1)
DataGrid1.CurrentRowIndex = ds.tables(0).Rows.Count - 1

However show us what is your datasource because when it is the dataview with a sort in it, it is of course not this.

I hope this helps already a little bit.

Cor

Nov 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Ashish Shridharan | last post by:
Hi All I have been trying to add a control to the header cell of a datagrid on my ASP.NET page. These controls are defined in the HTML as ASP.NET web controls. They are being added into the...
3
by: Bill C. | last post by:
Hello, I know this has been discussed a lot already because I've been searching around for information the last few weeks. I'm trying to implement a DataGridComboBoxColumn class. I've found...
5
by: BBFrost | last post by:
Win2000 ..Net 1.1 SP1 c# using Visual Studio Ok, I'm currently in a "knock down - drag out" tussle with the .Net 1.1 datagrid. I've come to realize that a 'block' of rows highlighted within...
2
by: pei_world | last post by:
I want to implement a key hit with enter to dropdown a combobox that is in the datagrid. in this case I need to override its original behaviours. I found some codes from the web. Does anyone know...
1
by: Rick | last post by:
Hello all, I hope all is well with you. I am having a seriously difficult time with this problem. Allow me to set up the problem. I have a System.Web.UI.Page with the following controls...
3
by: CVerma | last post by:
Hi, I have an embedded datagrid within a datalist. I am not able to perfrom paging in the datagrid. Any ideas? Here is my code: Here is my Simplegrid.cs file: using System; using...
2
by: CSL | last post by:
I am using the DataGrid in a Windows Application, how can I adjust the widths of each column individually.
7
by: Dave | last post by:
Are there any add-on products or samples available that can do the following in an vb.net datagrid I want to compare 2 rows in a datagrid - one row from one database and another row for another...
9
by: rn5a | last post by:
A Form has a DataGrid which displays records from a SQL Server 2005 DB table. Users can modify the records using this DataGrid for which I am using EditCommandColumn in the DataGrid. This is the...
2
by: =?Utf-8?B?Y3JlYXZlczA2MjI=?= | last post by:
I have a nested datagrid in a xaml file, the parent datagrid loads the vendor information and the details loads the documents for that vendor in a datagrid. Everything is working fine until I click...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.