Solved

vb.net windowsform DataGrid /dataset/update

Posted on 2004-09-21
11
602 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
 

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
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 …

896 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now