Solved

vb.net windowsform DataGrid /dataset/update

Posted on 2004-09-21
11
609 Views
Last Modified: 2010-08-05
hi,

I return a dataset (generated by storedProc) from a DLL to the client(windows form)  and bind it to vb.net DataGrid

Works fine. here is the code :

dim Obj as CPopulateDs
dim ds as new dataset
ds = Obj.getdata()  'function returns dataset to client
WindowsGrid.setdataBinding(ds,0)

Lets say dataGrid displays ID, firstName, LastName

Now I have 2 empty textboxes on form for displaying values of selected row when cliced on grid

TxtFirstname.text  =  ds.tables(0).DataGrid1.Items(DataGrid1.SelectedIndex).Cells(1).text

TxtLastName.text  = ds.tables(0).DataGrid1.Items(DataGrid1.SelectedIndex).Cells(2).text

Now the values are displayed in the textboxes. User can change and click update.

How can update be done in this scenario. what is that I have to do in the dll for update functionality
can an example be shown
0
Comment
Question by:sainavya1215
  • 4
  • 3
11 Comments
 
LVL 18

Expert Comment

by:DotNetLover_Baan
ID: 12119606
So you want to add update functionality in "CPopulateDs" class. That can be done. Create a sub there, which takes all these three fields as arguments. But make sure, that you store the ID with the click event of the Grid. Then just call that Sub using the same class object as you used for getdata().
-Baan
0
 

Author Comment

by:sainavya1215
ID: 12119788
should i update the DS used in previous code or should i write a different functioanlity for it instead of updating the dataset can an example be shown?
0
 

Author Comment

by:sainavya1215
ID: 12119840
SORRY there is change in code i posted........ Have i did the right thing. I want to update the Dataset (Dseries) used in my code.

I just need an example to be shown considering the folllowing code given below

here is the code:
Dim Dseries as new Dataset
DSeries = obj.GetDataset()
GrdGrid.setDatabinding(DSeries.Tables(0),"Nothing")


  Private Sub GrdBKSeries_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles GrdBKSeries.MouseUp

        Try
            Dim oInfo As DataGrid.HitTestInfo
            oInfo = Me.GrdGrid.HitTest(e.X, e.Y)
            Me.GrdGrid.Select(oInfo.Row)
            TxtFirstName.Text = dSeries.Tables(0).Rows(GrdBKSeries.CurrentCell.RowNumber).Item(1)
            TxtLastName.Text = dSeries.Tables(0).Rows(GrdBKSeries.CurrentCell.RowNumber).Item(2)
                 Catch ex As Exception
            MessageBox.Show(ex.Message.ToString, AppTitle)
        End Try


0
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 

Author Comment

by:sainavya1215
ID: 12119920
For test purpose I changed the text displayed in the 2 textboxes and in my updatebutton click event ... Though i changed the text i dont get the message "dataset data has changed" ... Whats going wrong. I want to update the same dataset used in my client form instead of just passing text values to be updated in my dll

if dSeries.haschanges then
       Messagebox.show("dataset data has changed")
         else
            Messagebox.show("dataset data hasnt changed")
end if

0
 
LVL 2

Expert Comment

by:ahmadfuwad
ID: 12120235
'take idx as global variable in the form
dim idx as integer

'code for set the textbox with the selected value
       Private Sub DataGrid1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGrid1.DoubleClick
        idx = Me.DataGrid1.CurrentRowIndex
        Me.TextBox1.Text = ods.Tables(0).Rows(idx).Item(1)
        Me.TextBox2.Text = ods.Tables(0).Rows(idx).Item(2)
    End Sub

'code for update dataset and datagrid at the same time by changing the value in textboxes
 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        ods.Tables(0).Rows(idx).Item(1) = Me.TextBox1.Text
        ods.Tables(0).Rows(idx).Item(2) = Me.TextBox2.Text

    End Sub
0
 
LVL 18

Expert Comment

by:DotNetLover_Baan
ID: 12122550
>>"Though i changed the text i dont get the message "dataset data has changed" "<< this is happening because you are just displaying the two data fields in the textBoxes, not BINDING it. You have to change something that is bound. Only then your Dataset will recognize the changes.
-Baan
0
 

Author Comment

by:sainavya1215
ID: 12131728
DotNetLver,
if the textboxes values are changed
dSeries.Tables(0).Rows(GrdBKSeries.CurrentCell.RowNumber).Item(1) = me.textbox1.text
dSeries.tables(0).rows(GrdBkSeries.currentCell.rowNumber).item(2) = me.textbox2.text

Will this work... Will the dataset (dseries) take the new changes in the textboxes ........Should I call dseries.update after this statement or not??

0
 
LVL 18

Accepted Solution

by:
DotNetLover_Baan earned 500 total points
ID: 12132859
try this..

dSeries.Tables(0).Rows(GrdBKSeries.CurrentCell.RowNumber).Item(1) = me.textbox1.text
dSeries.tables(0).rows(GrdBkSeries.currentCell.rowNumber).item(2) = me.textbox2.text
dSeries.AcceptChanges()
'Then update

-Baan
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question