473,569 Members | 2,762 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how do I call dataGridView_Ro wEnter event from within buttonSave_ Click event?

dataGridView1.R owEnter += new
DataGridViewCel lEventHandler(d ataGridView1_Ro wEnter);
private void buttonSave_Clic k(object sender, EventArgs e)
{
//how do I activate RowEnter event below to obtain the the CustomerID as
I did below??????? <----------------------
}

private void dataGridView1_R owEnter(object sender, DataGridViewCel lEventArgs
e)
{
Customer c = m_Customers[e.RowIndex];
MessageBox.Show (c.SID.ToString ());
}
Thank you,
-hazz
Feb 8 '06 #1
2 2164
private void buttonSave_Clic k(object sender, EventArgs e) {

Customer c = (CustomerdataGr idView1.Selecte dRows[0].DataBoundItem;
or
Customer c =
(Customer)dataG ridView1.Rows[dataGridView1.S electedCells[0].RowIndex].DataBoundItem;
// and then get the CustomerID property from the Customer object.
}

"hazz" <ha**@sonic.net > wrote in message
news:eG******** *****@TK2MSFTNG P09.phx.gbl...
dataGridView1.R owEnter += new
DataGridViewCel lEventHandler(d ataGridView1_Ro wEnter);
private void buttonSave_Clic k(object sender, EventArgs e)
{
//how do I activate RowEnter event below to obtain the the CustomerID as
I did below??????? <----------------------
}

private void dataGridView1_R owEnter(object sender,
DataGridViewCel lEventArgs e)
{
Customer c = m_Customers[e.RowIndex];
MessageBox.Show (c.SID.ToString ());
}
Thank you,
-hazz

Feb 8 '06 #2
You might consider writing a handy property:

private Customer SelectedCustome r
{
get
{
if (dataGridView1. SelectedRows.Co unt == 0)
{
return null;
}
else
{
return
(Customer)dataG ridView1.Select edRows[0].DataBoundItem;
}
}
}

which would make your code easier to read:

private void buttonSave_Clic k(object sender, EventArgs e)
{
Customer c = this.SelectedCu stomer;
if (c != null)
{
... do something with the customer ...
}
}

Feb 8 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
1555
by: Roger | last post by:
Hi All, I need to call a text box click event programatically. How would I call the following event procedure from another procedure within the same form: Private Sub TextBox2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox2.Click Thanks in advance. Roger.
2
20499
by: abs | last post by:
Hi all. Is that possible to call the onclick, onchange or other event from JS ? I mean how to make the browser think that user clicked the element (onclick event) ? Eg. I have <element onclick='myFunction()'> and I don't want to call the myFunction() by writing its name in the code but I want to call the onclick event without clicking :) I...
1
3014
by: jralford | last post by:
Hi, Another question from a C# newbie: I have a usercontrol class that includes a customized control. Now, if I create an instance of the class, and click on it, a click event is raised for the customized control within the class. This is good. What I also want is to raise a click event for the class itself. For instance,
4
4274
by: John | last post by:
Hi all, This really is quite an urgent matter. I have a page with multiple, dynamically-loaded user controls and when a user clicks on a button, the whole form is submitted. Now at this stage I know I need to call a function that will save data but I'm not sure exactly when to call this function. I've tried two ways and both seem to...
0
1628
by: luca | last post by:
Hi all. My problem is that I can't handle events raised from child components within a composite server control when the control is created dynamically. Everything works fine if the same control is defined within an aspx page <MyTag:MyControl id="MyControl1" runat="server">: MyControl handle succesfully events raised from its children. When...
22
3173
by: Ricky W. Hunt | last post by:
First, the subject probably doesn't use the correct terms but I'm not sure what it's called in VB. I'm writing a media player app. The subroutine that handles the "open file" button contains an If statement to see if a file was already playing and if so executes some code to stop the previous file from playing among other things. There's...
4
3158
by: John Wels | last post by:
Hi. How can I call some event in my code. Example: I have declared Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btntest.Click 'Code
41
4266
by: JohnR | last post by:
In it's simplest form, assume that I have created a usercontrol, WSToolBarButton that contains a button. I would like to eventually create copies of WSToolBarButton dynamically at run time based on some initialization information obtained elsewhere. Basically, I'm going to create my own dynamic toolbar where the toolbarbuttons can change. ...
5
1580
by: Lostdante via DotNetMonster.com | last post by:
Hi, I have a modal dialog box which i'm using to collect user data. what I want to do is when the user clicks the 'submit' button add the data to the database and then call the java script to close the window and pass a value back to the parent page. I've tried using RegisterStartupScript after the database update function but this...
0
7694
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7609
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7921
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8118
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7666
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7964
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6278
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
2107
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
936
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.