Solved

vb.net windowsform DataGrid /dataset/update

Posted on 2004-09-21
11
596 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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video discusses moving either the default database or any database to a new volume.

708 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

12 Experts available now in Live!

Get 1:1 Help Now