2009-09-10 21 views
6

में पंक्ति संख्या प्राप्त करना आपको पंक्ति संख्या DataGridView सेल कैसे मिलता है? विशेष रूप से, यदि किसी उपयोगकर्ता ने एक सेल चुना है, तो आप उस पंक्ति संख्या को कैसे प्राप्त कर सकते हैं? उपयोगकर्ता ने जो चुना है उसके आधार पर इसे किसी विशेष सेल तक पहुंचने की आवश्यकता है।डेटाग्रिड व्यू

मुझे पता है कि RemoveAt विधि का उपयोग फोकस पर निकालने के लिए किया जा सकता है, लेकिन आप स्पष्ट रूप से फोकस पर पंक्ति संख्या नहीं प्राप्त कर सकते हैं?

सहायता के लिए धन्यवाद!

उत्तर

17

आप बस पर RowIndex उपयोग कर सकते हैं current cell:

var row = dataGridView1.CurrentCell.RowIndex; 
0

यह लगभग एक ही है, लेकिन आप भी इस समाधान का उपयोग हो सकता है:

var row = dataGridView1.CurrentRow.Index 
0

एक और तरीका है आप के साथ उपयोगकर्ता इंटरैक्शन को ट्रैक करने की आवश्यकता है एक डेटाग्रिड व्यू: मेरे मामले में कुछ सामान्य कार्यों में अतिरिक्त प्रसंस्करण है जो Me.I_SelCol और Me.I_SelRow कॉलम और पंक्ति निर्देशांक का उपयोग करते हैं, लेकिन मैंने यह नहीं दिखाया है क्योंकि यह ओपी के लिए प्रासंगिक नहीं है।

सादर, रोब

Private Sub I_DataGridView_CurrentCellChanged(sender As Object, e As EventArgs) Handles I_DataGridView.CurrentCellChanged 

     If Me.I_DataGridView.CurrentCellAddress.X < 0 Or Me.I_DataGridView.CurrentCellAddress.Y < 0 Then Exit Sub 

     ' The Windows Me.I_DataGridView object will have already deselected the current cell and selected the 
     ' new cell as per user navigation using mouse or cursor keys. We just need to store the current 
     ' co-ordinates for the currently selected cell. 

     Me.I_SelCol = Me.I_DataGridView.CurrentCellAddress.X 
     Me.I_SelRow = Me.I_DataGridView.CurrentCellAddress.Y 

Exit Sub 
1

यह एक ठीक काम करता है।

Private Sub DataGridView1_RowPrePaint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewRowPrePaintEventArgs) Handles DataGridView1.RowPrePaint 

If e.RowIndex >= 0 Then 
     Me.DataGridView1.Rows(e.RowIndex).Cells(0).Value = e.RowIndex + 1 
    End If 
End Sub 
संबंधित मुद्दे