Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > General .NET
|
General .NET For general discussion of MICROSOFT .NET topics that don't fall within any of the other .NET forum subcategories or .NET language forums.  If your question is specific to a language (C# or Visual Basic) or type of application (Windows Forms or ASP.Net) try an applicable forum category. ** PLEASE BE SPECIFIC WITH YOUR QUESTION ** When posting here, provide details regarding the Microsoft .NET language you are using and/or what type of application (Windows/Web Forms, etc) you are working in, if applicable to the question. This will help others answer the question without having to ask.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the General .NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 10th, 2005, 12:27 PM
Registered User
 
Join Date: Feb 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Getting DataGrid Cell Data

Im working on a client with mouseover controls on a DataGrid to make life easier on a user who is very perticular as to how he wants to do things. However i cant pull the Data out of the Cell. I tried pulling it from the DataTable, but when the grid is resorted by the user the DataTable is not, and thus when the data i am pulling is incorrect. Is there a way to work around this? Im working in C# but i can read any .NET Language...
 
Old February 20th, 2005, 01:43 PM
Registered User
 
Join Date: Feb 2005
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I just did this the other day, to reformat a column in the datagrid. In it, I overloaded the data binding method of the datagrid so that I could display a link depending on the content of the cell. Hope it gives you an idea of how to access it.


Protected Sub myDataGrid_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles myDataGrid.ItemDataBound
If (e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem) Then
   If (e.Item.Cells(column_typeID).Text = "fldr") Then
      e.Item.Cells(column_fileID).Text = "<a href='ScreenFolders.aspx?objid=" + e.Item.Cells(column_fileID).Text + "' target='_blank'>View Folder</a>"
   ElseIf (e.Item.Cells(column_typeID).Text = "file") Then

      e.Item.Cells(column_fileID).Text = "<a href='Screenfiles.aspx?objid=" + e.Item.Cells(column_fileID).Text + "' target='_blank'>View File</a>"
      End If
   End If
End Sub
 
Old February 20th, 2005, 07:00 PM
Registered User
 
Join Date: Feb 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thats nice code... However im working with WinForms and the WinForm DataGrid. i Did however fix the problem.
C#
Code:
  BindingManagerBase bm = 
    ((System.Windows.Forms.DataGrid)sender).BindingContext[ 
      ((System.Windows.Forms.DataGrid)sender).DataSource, 
      ((System.Windows.Forms.DataGrid)sender).DataMember]; 
  DataRow dr = ((DataRowView)(bm.Current)).Row;
VB (Converted by hand from C#, hope its 100% correct.)
Code:
  Dim bm As BindingManagerBase = 
    CType(sender, System.Windows.Forms.DataGrid).BindingContext( 
      CType(sender, System.Windows.Forms.DataGrid).DataSource, 
      CType(sender, System.Windows.Forms.DataGrid).DataMember) 
  Dim dr As DataRow = CType(bm.Current, DataRowView).Row





Similar Threads
Thread Thread Starter Forum Replies Last Post
Blink Datagrid cell data?? vinodjangle ASP.NET 2.0 Professional 1 April 18th, 2008 09:51 AM
Copy data into cell by cell zone Excel VBA 2 September 4th, 2007 11:50 AM
Can't read new data from DataGrid cell Guest00 ASP.NET 1.0 and 1.1 Basics 3 October 17th, 2004 11:51 PM
DataGrid Cell mrideout BOOK: Beginning ASP.NET 1.0 0 August 17th, 2004 12:34 PM
How to add data to a DataGrid Cell. chiefouko VS.NET 2002/2003 2 July 28th, 2004 01:24 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.