Solved

vb.net windowsform DataGrid /dataset/update

Posted on 2004-09-21
11
616 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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Exit the loop 4 49
VB.Net. Reading xml value 6 30
Code enhancement 4 22
vb.net convert long time to mm:ss 23 13
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 …
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

860 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