सी # DataGridView चेकबॉक्स चेक घटना - एकाधिक पंक्तियों?

वोट
2

मैं कई स्तंभों और पंक्तियों के साथ एक DataGridView है। पहले कॉलम एक चेकबॉक्स होता है। मैं उपयोगकर्ता से अधिक चेकबॉक्स को चुनने के लिए और उसके बाद कोई कार्रवाई करने में सक्षम होना चाहता हूँ। उदाहरण के लिए अगर वे चुना जा सकता है और पारित एक messagebox में पंक्तियों 1 और 2 में चेक बॉक्स, पंक्तियों 1 और 2 में अन्य स्तंभों से डेटा का चयन करें।

मैं मैं यह करने के लिए checkbox_changed घटना उपयोग करने की आवश्यकता को जानते हैं। हालांकि मैं बाहर काम कर रहा है कि कैसे अनेक पंक्तियों के लिए यह करने के लिए परेशानी हो रही हूँ?

02/07/2009 को 14:36
का स्रोत उपयोगकर्ता
अन्य भाषाओं में...                            


4 जवाब

वोट
1

आप एक बटन पर क्लिक करने उपयोगकर्ता क्रिया करने के लिए चाहते हैं, तो क्या आप को संभाल करने की जरूरत है बटन की स्थिति के लिए क्लिक करें, नहीं चेक बॉक्स बदल दिया घटना है ... जब बटन क्लिक किया है, बस की सभी पंक्तियों के माध्यम से जाने के लिए अपने DataGridView और एक जाँच चेकबॉक्स साथ पंक्तियों पर कोई क्रिया।

02/07/2009 को 15:05
का स्रोत उपयोगकर्ता

वोट
5

बटन पर क्लिक करने पर घटना कार्य करें:

static int SelectColumnIndex = 0;
PerformAction_Click(object sender, System.EventArgs e)
{
    string data = string.Empty;
    foreach(DataGridViewRow row in MyDataGridView.Rows)
    {
      if(row.Cells[SelectColumnIndex].Value!=null &&
             Convert.ToBoolean(row.Cells[SelectColumnIndex].Value) == true)
      {
        foreach(DataGridViewCell cell in row.Cells)
        {
          if(cell.OwningColumn.Index!= SelectColumnIndex)
          {
            data+= (cell.Value + " ") ; // do some thing
          }
        }
        data+="\n";
      }
   }
   MessageBox.Show(data, "Data");
}
02/07/2009 को 15:08
का स्रोत उपयोगकर्ता

वोट
1
static int SelectColumnIndex = 0;

PerformAction_Click(object sender, System.EventArgs e)
{
    string data = string.Empty;    

    foreach(DataGridViewRow row in MyDataGridView.Rows)     
    {
        if(row.Cells[SelectColumnIndex].Value != null 
            &&
         Convert.ToBoolean(row.Cells[SelectColumnIndex].Value) == true)       
        {
            foreach(DataGridViewCell cell in row.Cells)        
            {
                if (cell.OwningColumn.Index != SelectColumnIndex)                               
                {
                    data+= (cell.Value + " ") ; // do some thing           
                 }
            }

            data+="\n";
        }
    }

    MessageBox.Show(data, "Data");
}
01/06/2011 को 05:32
का स्रोत उपयोगकर्ता

वोट
0

मुझे लगता है कि आप किसी भी घटना न मैं इस कोड इस समस्या का समाधान करने की जरूरत है:

//In Fill DataGridViewEvent :
        DataGridViewCheckBoxColumn ChCol = new DataGridViewCheckBoxColumn();
        ChCol.Name = "CheckedRow";
        ChCol.HeaderText = "انتخاب";
        ChCol.Width = 50;
        ChCol.TrueValue = "1";
        ChCol.FalseValue = "0";
        dg.Columns.Insert(0, ChCol);

// In Button Event put these codes:

            try
            {
                MessageBox.Show(row.Cells[2].Value.ToString() + " --> " +
                row.Cells["CheckedRow"].Value.ToString());
            }
            catch
            {
                // Nothing Act
            }


enter code here

इस पैरामीटर द्वारा आपका आउटपुट: Itemid -> 1 की जांच की गई // के लिए मान -> 0 // अनियंत्रित मान ItemID के लिए

अब आप पंक्तियों मूल्य आपके कार्य के लिए मैं इस कोड का परीक्षण के रूप में वापसी 1 फ़िल्टर कर सकते हैं और यह मेरे लिए काम

18/01/2014 को 20:16
का स्रोत उपयोगकर्ता

Cookies help us deliver our services. By using our services, you agree to our use of cookies. Learn more