I have problem databinding the DataGrid with DataView/DataSet after the
filter...
I create the following proceudre in order for user to filter as many as they
want, but the following code is only allow user to filter the first time,
when they tried the second time, the speficied cast error message will
prompt one....
I create a mydataset1 first, and the mydataset1 data source was getting from
DataGrid.DataSource.
then I create a DataView in order for me to filter....
after I enter the criteria, then will filter successfully the first time,
but not second time.
the I bind the DataGrid to DataView together......
The first filter is always successfully, I just can not filter the same data
second time...
I suspect it the DataView and DataSet problem, because at first I bind
datagrid1 and get the data source of datagrid1 form Dataset, but at the end
I bing the Datagird to the Dataview also.....so there are some error....i
think....
I just have no idea how to bind the Datagrid with Dataview, and allow user
to filter as many time as they want.....
could someone pls guide me.... here are the CODE
Try
Dim mydataset1 As New DataSet
mydataset1 = DataGrid1.DataSource
Dim mydataview As New
DataView(mydataset1.Tables(Global.strTblName))
Dim strInput
strInput = InputBox("test")
mydataview.RowFilter = "Custno = " & strInput & ""
DataGrid1.Datasource= mydataview
' DataGrid1.DataSource = mydataset1
' DataGrid1.DataMember = GlobalDBExplorer.strTblName
Catch err As InvalidCastException
MsgBox(err.Message)
Catch err As Exception
MsgBox(err.Message)
End Try 17 2653
APK,
You only have to bind the dataview one time to your datagrid.
There cannot be more datasources.
I have the idea that you are creating everytime a new dataview and try to
bind that new one against your datagrid.
I hope this helps,
Cor
Hi Cor,
my first problem is that....I dun have a fix dataset for me to bind to
datagrid1....
It is dynamically bind to datasetA or datasetB...depend on user's choice...
so I have to create anotehr local dataset1 and set to
mydataset1 = datagrid.datasource
after i get the mydataset1, then I create Dataview....
and user allow to do filter on dataview, then after the filtering, then
datagrid1 bind to dataview.....
please note that...I am using DataGrid = myDataView....
so for other feacture, i can not get the myDataSet1 = DataGrid.DataSource,
because i can not simply quote Dateset1 = DataView..
so I wish to know how the DataView can update the Dataset1.....
if I were to allow to create only one time dataview, may I know where should
I create the DataView ?
"Cor Ligthert" <no************@planet.nl> wrote in message
news:e5**************@tk2msftngp13.phx.gbl... APK,
You only have to bind the dataview one time to your datagrid. There cannot be more datasources.
I have the idea that you are creating everytime a new dataview and try to bind that new one against your datagrid.
I hope this helps,
Cor
Hi,
Do it like this,
dim myDataView = myDataTable.DefaultView;
If you take DefaultView from a table and filter it with your criteria,
when you change a values in the dataview the change will pass through
to the underlying datatable as well.
So no need to bind it once again you may comment this
DataGrid1.Datasource= mydataview
Hope this helps,
Cheers,
Arun. www.innasite.com
APK,
You can use as much dataviews as you want, however a datagrid can only one
use one datasource.
Probably the best choise for you ia uainf the defaultview what is in every
datatable which is a dataview.
Someting as setting it every time when the user have changed.
\\\
dataset.table(x).defaultview.rowfilter = "xx = " & y & "'"
///
Than you can use one time
\\\
Datagrid1.datasource = dataset.table(x).defaultview
///
I hope this helps,
Cor
hi cor, arun...
another problem.....
how could I bind the data to myDataview or myDataset ?...
Cor, you mentioned
dataset.table(x).defaultview.rowfilter = "xx = " & y & "'"
my problem is......my dataset is nothing at the very first beginning...
I have to based on datagrid data then only can decide my dataset1...
that is the reason that I set mydataset1 = datagrid.datasource.....
after i set the mydataset1 = datagrid.datasource, then i type the one u
mentioned, and bind it accordinly what u had mentioned....but i still
getting the error "sepcialized cast error"......
because i bind the dataset based on datagrid.datasrouce.....
I just wonder if I bind it wrongly ? or anyway way to solve that problem ?
my dataset is nothing at the beginning, I get the dataset data based on
datagird data.
mydataset = Datagrid.datasource......
after getting mydataset, then I using defauly view to bind to datagrid......
but I am still getting error when i did it repeatly....
"Cor Ligthert" <no************@planet.nl> wrote in message
news:Oa**************@tk2msftngp13.phx.gbl... APK,
You can use as much dataviews as you want, however a datagrid can only one use one datasource.
Probably the best choise for you ia uainf the defaultview what is in every datatable which is a dataview.
Someting as setting it every time when the user have changed.
\\\ dataset.table(x).defaultview.rowfilter = "xx = " & y & "'" ///
Than you can use one time
\\\ Datagrid1.datasource = dataset.table(x).defaultview ///
I hope this helps,
Cor
To simply what I want to do....
I create a Dataset with a lot of infomration, then i create Dataview to
filter out all unwanted info....so that all the info in the Dataview is all
the information that I want ......
now I want to update the dataview to a dataset...cos I might perform other
update or delete command to update dataset........
pls guide me how to update DataView to Dataset ?
1- Dataset with All Info
2- create Dataview and filter out all unwanted info
3- update back Dataview to previous Dataset...
how to do that ?
so perhaps, my dataset have 1000 records, but after I did the filter, only
50 records i want...
so i update 50 back to dataset, and delete other 950 records....
hope someone to guide me...thank you....
" A_PK" <pk***@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl... hi cor, arun...
another problem.....
how could I bind the data to myDataview or myDataset ?...
Cor, you mentioned dataset.table(x).defaultview.rowfilter = "xx = " & y & "'"
my problem is......my dataset is nothing at the very first beginning... I have to based on datagrid data then only can decide my dataset1...
that is the reason that I set mydataset1 = datagrid.datasource..... after i set the mydataset1 = datagrid.datasource, then i type the one u mentioned, and bind it accordinly what u had mentioned....but i still getting the error "sepcialized cast error"......
because i bind the dataset based on datagrid.datasrouce.....
I just wonder if I bind it wrongly ? or anyway way to solve that problem ? my dataset is nothing at the beginning, I get the dataset data based on datagird data. mydataset = Datagrid.datasource......
after getting mydataset, then I using defauly view to bind to datagrid......
but I am still getting error when i did it repeatly.... "Cor Ligthert" <no************@planet.nl> wrote in message news:Oa**************@tk2msftngp13.phx.gbl... APK,
You can use as much dataviews as you want, however a datagrid can only one use one datasource.
Probably the best choise for you ia uainf the defaultview what is in every datatable which is a dataview.
Someting as setting it every time when the user have changed.
\\\ dataset.table(x).defaultview.rowfilter = "xx = " & y & "'" ///
Than you can use one time
\\\ Datagrid1.datasource = dataset.table(x).defaultview ///
I hope this helps,
Cor
APK,
I made a little sample for you.
\\\Needs a datagrid and a button on a form
Private ds As New DataSet
Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim dt As New DataTable("APK")
dt.Columns.Add("A")
dt.LoadDataRow(New Object() {"1"}, True)
dt.LoadDataRow(New Object() {"2"}, True)
dt.LoadDataRow(New Object() {"3"}, True)
ds.Tables.Add(dt)
DataGrid1.DataSource = ds.Tables("APK").DefaultView
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
If ds.Tables("APK").DefaultView.RowFilter = "A = '2'" Then
ds.Tables("APK").DefaultView.RowFilter = ""
Else
ds.Tables("APK").DefaultView.RowFilter = "A = '2'"
End If
End Sub
///
I hope this helps,
Cor
Hi Cor, i understand what u mean....
but after I have done the filter, and set the DataGrid1.DataSource =
ds.Tables("APK").DefaultView
....I can perform filter feature actually. just that when I do know how to
retierve the filtered datasource and bind them to a new dataset to perform
other feature....
When I click other buttton, not the button u mentioned.....I need to know
what dataset is binding that datagrid. so in other button, i type myDataset
= Datagrid1.datasource. then i will get the specialied cast error...cos my
Datagrid.datasource is binding to a dataview, not dataset.... after I filter
all infomration liao, i have problem binding those information to other
dataset1...
u tried the following sure got problem
Declare a global dataset as dsFilter....
Try
Dim strInput
strInput = InputBox("test")
dsFilter.Tables(GlobalDBExplorer.strTblName).Defau ltView.RowFilter
= "ColumnName = ' & strInput & '"
DataGrid1.DataSource =
dsFilter.Tables(GlobalDBExplorer.strTblName).Defau ltView
Catch err As InvalidCastException
MsgBox(err.Message)
Catch err As Exception
MsgBox(err.Message)
End Try
I have no problem up to here.....but I want to
get the Datasource from DataGrid, then I will have problem
can i do anything like
mydataset = Datagird.datasource ?
mydataset.Tables(TableName) = DataGrid.Datasource ?
I need to get the Datasource from DataGrid from my other features....
I just no idea how to do that .....
but I have no problem if it is dataset.....
I can simply type mydataset = DataGrid.Datasource
Since I am binding to a View, i can no longer get the datasource from
datagrid1 by just typing mydataset = datagrid.datasource....
pls guide
"Cor Ligthert" <no************@planet.nl> wrote in message
news:Og**************@TK2MSFTNGP12.phx.gbl... APK,
I made a little sample for you.
\\\Needs a datagrid and a button on a form Private ds As New DataSet Private Sub Form1_Load(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles MyBase.Load Dim dt As New DataTable("APK") dt.Columns.Add("A") dt.LoadDataRow(New Object() {"1"}, True) dt.LoadDataRow(New Object() {"2"}, True) dt.LoadDataRow(New Object() {"3"}, True) ds.Tables.Add(dt) DataGrid1.DataSource = ds.Tables("APK").DefaultView End Sub Private Sub Button1_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles Button1.Click If ds.Tables("APK").DefaultView.RowFilter = "A = '2'" Then ds.Tables("APK").DefaultView.RowFilter = "" Else ds.Tables("APK").DefaultView.RowFilter = "A = '2'" End If End Sub ///
I hope this helps,
Cor
i still have a sub Call WriteXML...using the filtered data to write to XML
Private Sub WriteXML()
Dim mydataset As New DataSet
mydataset = DataGrid1.DataSource
mydataset.WriteXml(Application.StartupPath & "\Demo.xml")
End Sub
I can simply use mydataset = DataGrid.Datasource, and get the reference, and
export as XML file.
but after I set to defauly view or use dataview, i can no longer the the
datasource references.
I just wonder how should I get the above mydataset bind to the filtered
datagrid datasource.
"Cor Ligthert" <no************@planet.nl> wrote in message
news:Og**************@TK2MSFTNGP12.phx.gbl... APK,
I made a little sample for you.
\\\Needs a datagrid and a button on a form Private ds As New DataSet Private Sub Form1_Load(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles MyBase.Load Dim dt As New DataTable("APK") dt.Columns.Add("A") dt.LoadDataRow(New Object() {"1"}, True) dt.LoadDataRow(New Object() {"2"}, True) dt.LoadDataRow(New Object() {"3"}, True) ds.Tables.Add(dt) DataGrid1.DataSource = ds.Tables("APK").DefaultView End Sub Private Sub Button1_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles Button1.Click If ds.Tables("APK").DefaultView.RowFilter = "A = '2'" Then ds.Tables("APK").DefaultView.RowFilter = "" Else ds.Tables("APK").DefaultView.RowFilter = "A = '2'" End If End Sub ///
I hope this helps,
Cor
APK,
When you want to set another datasource to a datagrid than you first have to
do.
datagrid.datasource = nothing
I hope this helps,
Cor
APK
This is a complet new question and reading in the ADONET newsgroup I now
understand what you are after and have even for that a sample. However I
think that it becomes to much confusing for people who reads those threads
in future when the questions are placed in more newsgroups and they don't
see the relation between question and answers, so I stop with answering in
this thread.
Cor
I apologize for doing that....
It is because that after I post my query, then I only realized that there is
still one adonet newgroup which might be related to my topic, so I post my
question to that newsgroup...
I dun mean do that that....
If you do know the solution, pls kindly let me know.
THank you very much
"Cor Ligthert" <no************@planet.nl> wrote in message
news:uO****************@TK2MSFTNGP10.phx.gbl... APK
This is a complet new question and reading in the ADONET newsgroup I now understand what you are after and have even for that a sample. However I think that it becomes to much confusing for people who reads those threads in future when the questions are placed in more newsgroups and they don't see the relation between question and answers, so I stop with answering in this thread.
Cor
Hi APK,
Here is a sample code snippet, Thanks Cor for the code and I have
changed a little to work for your requirement,
Try this code.
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Try
Dim dt As New DataTable("APK")
dt.Columns.Add("A")
dt.LoadDataRow(New Object() {"1"}, True)
dt.LoadDataRow(New Object() {"2"}, True)
dt.LoadDataRow(New Object() {"3"}, True)
ds.Tables.Add(dt)
DataGrid1.DataSource = dt
Catch err As InvalidCastException
MsgBox(err.Message)
Catch err As Exception
MsgBox(err.Message)
End Try
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim ds1 As New DataSet
Dim dp As New DataTable
Dim i As Int32
dp = ds.Tables("APK").Clone
Dim dt() As DataRow = ds.Tables("APK").Select("A = '2'")
'Use ImportRow method to copy from Products table to its clone.
For i = 0 To dt.Length - 1
dp.ImportRow(dt(i))
Next
ds1.Tables.Add(dp)
DataGrid1.DataSource = dp
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
Dim i As Int32
Dim dt1 As New DataTable
dt1 = CType(DataGrid1.DataSource, DataTable)
dt1.DataSet.WriteXml("\Demo.xml")
End Sub
Hope this helps,
Cheers,
Arun. www.innasite.com
Arun,
I readed in the ADONET newsgroup that this is probably what APX is needed.
However as you did, is this kind of answering confusing on questions in more
newsgroups.
(Changed a lot in this message so watch typos)
\\\
Dim dsNew as new dataset
Dim dv As New DataView(OriginalDataset.Tables("whatever"))
dv.RowFilter = "A = '1"
Dim dtnew As DataTable = OriginalDataset.Tables("whatever").Clone
For Each dvr As DataRowView In dv
dtnew.ImportRow(dvr.Row)
Next
dt.Clear()
dsNew.Tables.Add(dtnew)
dsNew.WriteXML("C:\mydataset.xml")
///
:-)
Cor
Hi Arun,
thank for the code...
another question...just wonder if there is a way to bind the datagrid back
to dataset instead of dataview and datatable ?
because if I do filter, then have to bind my datagrid to datatable or
dataview,
if I dun do filter, then my datagrid will bind to dataset....
Without Filter....following is my WriteXML code
Dim mydataset As New DataSet
mydataset = DataGrid1.DataSource
mydataset.WriteXmlSchema(Application.StartupPath &
"\DBexplorer\Demo.xsd")
mydataset.WriteXml(Application.StartupPath &
"\DBexplorer\Demo.xml")
WithFilter...following is my WriteXML code....
Dim dt1 As New DataTable
dt1 = CType(DataGrid1.DataSource, DataTable)
dt1.DataSet.WriteXml(Application.StartupPath &
"\DBexplorer\\Demo.xml")
so if I have done filter, then the code gave u will be working,
if i have not done filter, then the code u gave me will not be wokring....
so they all get datagrid.datasource from different source. one from Dataset,
one from either Dataview and DataTable...
how could I make all consistent ?
"Arun" <ar***************@gmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com... Hi APK,
Here is a sample code snippet, Thanks Cor for the code and I have changed a little to work for your requirement,
Try this code.
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Try Dim dt As New DataTable("APK") dt.Columns.Add("A") dt.LoadDataRow(New Object() {"1"}, True) dt.LoadDataRow(New Object() {"2"}, True) dt.LoadDataRow(New Object() {"3"}, True) ds.Tables.Add(dt) DataGrid1.DataSource = dt Catch err As InvalidCastException MsgBox(err.Message) Catch err As Exception MsgBox(err.Message) End Try
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim ds1 As New DataSet Dim dp As New DataTable Dim i As Int32 dp = ds.Tables("APK").Clone Dim dt() As DataRow = ds.Tables("APK").Select("A = '2'") 'Use ImportRow method to copy from Products table to its clone. For i = 0 To dt.Length - 1 dp.ImportRow(dt(i)) Next ds1.Tables.Add(dp) DataGrid1.DataSource = dp End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Dim i As Int32 Dim dt1 As New DataTable dt1 = CType(DataGrid1.DataSource, DataTable) dt1.DataSet.WriteXml("\Demo.xml") End Sub
Hope this helps,
Cheers, Arun. www.innasite.com
APK,
With or without filter
Dim dt1 As New DataTable
dt1 = CType(DataGrid1.DataSource, DataTable)
dt1.DataSet.WriteXml (Application.StartupPath &
"\DBexplorer\\Demo.xml")
This should have to work, Have you tried it!!!
Cheers,
Arun.
Well,,, thank for Arun and Cor...
"Arun" <ar***************@gmail.com> wrote in message
news:11*********************@l41g2000cwc.googlegro ups.com... APK,
With or without filter
Dim dt1 As New DataTable dt1 = CType(DataGrid1.DataSource, DataTable) dt1.DataSet.WriteXml (Application.StartupPath & "\DBexplorer\\Demo.xml")
This should have to work, Have you tried it!!!
Cheers, Arun. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: DelphiBlue |
last post by:
I have a Nested Datagrid that is using a data relations to tie the parent
child datagrids together. All is working well with the display but I am
having some issues trying to sort the child...
|
by: Guy Noir |
last post by:
I am having trouble wrapping my head around a datagrid and datasource.
I have it working, sort-of, but I'm having trouble refreshing my views.
Here's what I have:
A dataAdapter and dataSet...
|
by: Alpha |
last post by:
I have a window application. In one of the form, a datagrid has a dataview
as its datasource. Initial filtering result would give the datavew 3 items.
When I double click on the datagrid to edit...
|
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...
|
by: tshad |
last post by:
Is there a way to carry data that I have already read from the datagrid from
page to page?
I am looking at my Datagrid that I page through and when the user says get
the next page, I have to go...
|
by: suresh |
last post by:
frenz,
i need to disable the add new record mode in datarid.
i just want to modify the existing records in the
grid...but i dont want to add new records..how do i do
that?
-suresh
|
by: Ron L |
last post by:
I have a dataset whose source is a SQL 2k stored procedure that I am trying
to display in a datagrid. This datasource has 4 columns that I am
interested in here, a text column and 3 value columns...
|
by: Datatable Dataset Datagrid help |
last post by:
Hi I am somewhat confused, I am new at VB.net
I use XML data,
I have a datagrid,
I created a datatable so that I can create a custom format like true is this
graphic false is this graphic and...
|
by: Art |
last post by:
Hi,
Once again, I'm stuck.
I want to view a table using a DataGrid. I'd like to fiter that view by
criteria on various fields.
So far, I've created a DataAdapter, generated a DataSet and...
|
by: Rina0 |
last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM)
The start time is equivalent to 19:00 (7PM) in Central...
|
by: erikbower65 |
last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps:
1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal.
2. Connect to...
|
by: erikbower65 |
last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA:
1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
|
by: Taofi |
last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same
This are my field names
ID, Budgeted, Actual, Status and Differences
...
|
by: DJRhino |
last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer)
If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _
310030356 Or 310030359 Or 310030362 Or...
|
by: lllomh |
last post by:
How does React native implement an English player?
|
by: Mushico |
last post by:
How to calculate date of retirement from date of birth
|
by: DJRhino |
last post by:
Was curious if anyone else was having this same issue or not....
I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
| | |