473,320 Members | 1,865 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,320 software developers and data experts.

populate textbox from dataview

How can I populate a textbox from a dataview? I have a dataset i'm filtering
on and i want to populate several textboxes based on that filter.

How can i get that to work?

I've tried:

dsDetails = GetCars()
dvDetails = New DataView
With dvDetails
.Table = dsDetails.Tables(0)
.RowFilter = "CARMAKE=" & "'" & strModel& "'"
End With
txtName.DataBindings("NAME").ToString()

and i get this error(s)
Object reference not set to an instance of an object

or I get:

This would cause tow bindings in the collection to bind to the same property
Parameter name: binding

and i'm using this code
txtName.DataBindings.Add(New Binding("Text", dvDetails, "NAME"))

am I missing something or can this not be done?
Nov 21 '05 #1
14 3619
Barney - you need to ensure that you have a DataBinding for the textbox
before you reference it like that. If the bindings are already set - you
don't need to reset them each time. If you get rid of this line
txtName.DataBindings("NAME").ToString() Do you still get the exception?

--
W.G. Ryan, MVP

www.tibasolutions.com | www.devbuzz.com | www.knowdotnet.com
"Barney" <Ba****@discussions.microsoft.com> wrote in message
news:49**********************************@microsof t.com...
How can I populate a textbox from a dataview? I have a dataset i'm filtering on and i want to populate several textboxes based on that filter.

How can i get that to work?

I've tried:

dsDetails = GetCars()
dvDetails = New DataView
With dvDetails
.Table = dsDetails.Tables(0)
.RowFilter = "CARMAKE=" & "'" & strModel& "'"
End With
txtName.DataBindings("NAME").ToString()

and i get this error(s)
Object reference not set to an instance of an object

or I get:

This would cause tow bindings in the collection to bind to the same property Parameter name: binding

and i'm using this code
txtName.DataBindings.Add(New Binding("Text", dvDetails, "NAME"))

am I missing something or can this not be done?

Nov 21 '05 #2
Barney,

I am curious, why are you using your code like this
dsDetails = GetCars()
dvDetails = New DataView
With dvDetails
.Table = dsDetails.Tables(0)
.RowFilter = "CARMAKE=" & "'" & strModel& "'"
End With
txtName.DataBindings("NAME").ToString()

You know that with this you type more characters and is used one extra
instruction (not that the last is in my idea important).

And while busy your code can be to show the "name" in the txtName confirm
the currencymanager
\\\
dsDetails = GetCars()
dvDetails as New DataView(dsDetails.Tables(0))
dvDetails.RowFilter = "CARMAKE=" & "'" & strModel& "'"
txtName.DataBindings.Add(New Binding("Text", dvDetails, "NAME"))
///
I hope this helps?

Cor
Nov 21 '05 #3
yes i still get the error

"W.G. Ryan eMVP" wrote:
Barney - you need to ensure that you have a DataBinding for the textbox
before you reference it like that. If the bindings are already set - you
don't need to reset them each time. If you get rid of this line
txtName.DataBindings("NAME").ToString() Do you still get the exception?

--
W.G. Ryan, MVP

www.tibasolutions.com | www.devbuzz.com | www.knowdotnet.com
"Barney" <Ba****@discussions.microsoft.com> wrote in message
news:49**********************************@microsof t.com...
How can I populate a textbox from a dataview? I have a dataset i'm

filtering
on and i want to populate several textboxes based on that filter.

How can i get that to work?

I've tried:

dsDetails = GetCars()
dvDetails = New DataView
With dvDetails
.Table = dsDetails.Tables(0)
.RowFilter = "CARMAKE=" & "'" & strModel& "'"
End With
txtName.DataBindings("NAME").ToString()

and i get this error(s)
Object reference not set to an instance of an object

or I get:

This would cause tow bindings in the collection to bind to the same

property
Parameter name: binding

and i'm using this code
txtName.DataBindings.Add(New Binding("Text", dvDetails, "NAME"))

am I missing something or can this not be done?


Nov 21 '05 #4
I want to filter out the dataset (dataview) and only show the data in the
text box were it equals the users selection.

instead of creating another SQL and another hit to the DB i thought this
would be easier and a better performance.
instead of "select * from table where ID = " & selection "
"Cor Ligthert" wrote:
Barney,

I am curious, why are you using your code like this
dsDetails = GetCars()
dvDetails = New DataView
With dvDetails
.Table = dsDetails.Tables(0)
.RowFilter = "CARMAKE=" & "'" & strModel& "'"
End With
txtName.DataBindings("NAME").ToString()

You know that with this you type more characters and is used one extra
instruction (not that the last is in my idea important).

And while busy your code can be to show the "name" in the txtName confirm
the currencymanager
\\\
dsDetails = GetCars()
dvDetails as New DataView(dsDetails.Tables(0))
dvDetails.RowFilter = "CARMAKE=" & "'" & strModel& "'"
txtName.DataBindings.Add(New Binding("Text", dvDetails, "NAME"))
///
I hope this helps?

Cor

Nov 21 '05 #5
Barney,

I did mean why the "with" clause. For the rest I showed how you can do what
you want, some rows lower in my answer.

Cor
Nov 21 '05 #6
I follow, just a habit i developed.

even with the example you provided, i still can't pop a text box.

"Cor Ligthert" wrote:
Barney,

I did mean why the "with" clause. For the rest I showed how you can do what
you want, some rows lower in my answer.

Cor

Nov 21 '05 #7
Barney,

Strange as it looks are this "CARMAKE" and "NAME" you use in a windowform
case sensitive values (not in a webform). And I use nice spaces between the
selections however I don't know if that hurts.

Are you sure the cases are right?

Cor
Nov 21 '05 #8
I got it working, sort of. when i first load the form and select a cell in my
datagrid, the textbox is populate correctly, then when i select another cell
i get this error message:

This would cause two bindings in the collection to bind to the same
property. paramter name binding:

how can i get it to work when i select a new selection in my grid?


"Cor Ligthert" wrote:
Barney,

Strange as it looks are this "CARMAKE" and "NAME" you use in a windowform
case sensitive values (not in a webform). And I use nice spaces between the
selections however I don't know if that hurts.

Are you sure the cases are right?

Cor

Nov 21 '05 #9
Barney,

What code are you using now?
And how do you set the dataview to the datagrid.

Cor
Nov 21 '05 #10
here is what i have:

dsDetails = GetCars()
Dim dvDetails As New DataView(dsDetails.Tables(0))
dvDetails.RowFilter = "CARMAKE=" & "'" & strModel & "'"
txtName.DataBindings.Add("Text", dvDetails, "NAME")
Catch ex As Exception
MessageBox.Show("The following error has occurred: " &
ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try

"Cor Ligthert" wrote:
Barney,

What code are you using now?
And how do you set the dataview to the datagrid.

Cor

Nov 21 '05 #11
Barney,

You did not show the datagrid as I asked, however when it is like this

dsDetails = GetCars()
Dim dvDetails As New DataView(dsDetails.Tables(0)) datagrid1.datasource = dvDetails txtName.DataBindings.Add("Text", dvDetails, "NAME")


Than will in the textbox the current selected row be displayed from the
datagrid.
(What is done by the bindingcontext and the currencymanager)

Is that where you are after?

Cor
Nov 21 '05 #12
what i have is a function that talks to my db and gets me all the data to
populate the datagrid. That function returns a dataset, so in my form_Load i
have code such as
datagrid1.datasource = GetCars.Table(0) which populates the grid just like i
want. Then i have code in the datagrid1_selectionChanged to populate the
textboxes based on the users selection (the cell they clicked on). The user
can select 1 at a time so when the pick on then them details show up, if they
select another one then detais for that selection need to be displayed and so
on. I can get the first selection to work correctly, its when I choose
another one is when i get the error

I'm able to do this on a asp.net web form, so why will this not work on a
winForm?

"Cor Ligthert" wrote:
Barney,

You did not show the datagrid as I asked, however when it is like this

dsDetails = GetCars()
Dim dvDetails As New DataView(dsDetails.Tables(0))

datagrid1.datasource = dvDetails
txtName.DataBindings.Add("Text", dvDetails, "NAME")


Than will in the textbox the current selected row be displayed from the
datagrid.
(What is done by the bindingcontext and the currencymanager)

Is that where you are after?

Cor

Nov 21 '05 #13
Why don't you than try to change it as I told.

You can do it as well like this.

dsDetails = GetCars()
txtName.DataBindings.Add("Text", dsDetail.Tables(0), "NAME")
datagrid1.datasource = dsDetail.Tables(0)

Dont't compare the webform datagrid with the winform datagrid, that is done
by a lot of winform programmers for a webform datagrid. It are both grids
which has a datasource and with that is in my opinin all said.

Cor
Nov 21 '05 #14
I'll give this a shot, but the textboxes are only populated based on the
selection made by the user in the datagrid. The text box is not in the
datagrid, it is on the form below the grid. I'm not sure if your thinking the
textbox is in the grid or not. its not in the grid

"Cor Ligthert" wrote:
Why don't you than try to change it as I told.

You can do it as well like this.

dsDetails = GetCars()
txtName.DataBindings.Add("Text", dsDetail.Tables(0), "NAME")
datagrid1.datasource = dsDetail.Tables(0)

Dont't compare the webform datagrid with the winform datagrid, that is done
by a lot of winform programmers for a webform datagrid. It are both grids
which has a datasource and with that is in my opinin all said.

Cor

Nov 21 '05 #15

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

Similar topics

1
by: Job Lot | last post by:
My DataGrid is bound to a datatable named “dtClient” with following columns Date, BalanceCF, Income, Expenses, Withdrawls and BalanceCF. BalanceCF is an expression column. The column Withdrawals...
2
by: Mark | last post by:
I am attempting to populate several textbox controls from VBA code. With each attempt, I get the following error: "The macro or function set to the BeforeUpdate or ValidationRule property for...
13
by: Paul Slavin | last post by:
I have a textbox bound to a dataview, when I update the text in the textbox no changes take place in the underlying dataset. Why is this?? any answers appreciated, as to due to the underlying...
3
by: Karunakararao | last post by:
Hi All i have 40,000 records. populate the total records in Datagrid . it's taken time I need to populate the first 2000 records After the need to populate next 2000 records. how can i do...
0
by: Carlos Lozano | last post by:
Hi, I have to populate a grid from a data table. I do not know how big the table can grow and would like to plan ahead to avoid problems. I will give the user options to filter the data to show...
1
by: JIM.H. | last post by:
Hello, Here is the part of my code, I need to add a datagrid and populate is from this sql string. Can you write the rest of the code? Dim Da As New OdbcDataAdapter Dim Ds As New DataSet Dim...
3
by: crjunk | last post by:
I have 4 different databases that I'm having to pull data from in order to populate a datagrid. I am able to do this, but my problem is that because I'm pulling the data from 4 different...
6
by: MadCrazyNewbie | last post by:
Hey Group, I have the following code listed below: On my Winform I have 3 List Box`s and a Text Box. When I click on Catagories on my first ListBox it lists the Sub Catagories for that in the...
1
by: rn5a | last post by:
I was using a DataView to bind records from a DB table to a DataGrid using the following code: Dim sqlDapter As SqlDataAdapter Dim dSet As DataSet Dim dView As DataView sqlDapter = New...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, youll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
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: Shllpp 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.