简体   繁体   English

如何在C#Windows应用程序中将选中的列表框的选定项添加到datagridview中的特定列?

[英]how can i get the selected items of a checked listbox to a particular column in datagridview in c# windows application?

    string items;
    string total;

    private void checkedListBox1_SelectedValueChanged(object sender, EventArgs e)
    {

        foreach (string index in checkedListBox1.CheckedItems)
        {
            for (int cnt = 0; cnt < checkedListBox1.Items.Count; cnt++)
                // total_items.(getdata.Items[index].ToString());
                total = index.ToString();     
        }
        dataGridView1.Columns.Add("Items", "Choosed Items");
        dataGridView1.Rows.Add(total);
        dataGridView1.ClearSelection();
    }

I think you haven`t any other variant for add rows to datagridView. 我认为您没有其他向datagridView添加行的其他变体。

private void listBox1_SelectedIndexChanged(object sender, System.EventArgs e)
{  
   if(listBox1.SelectedIndex != -1)  {         
       // Get the currently selected item in the ListBox.
       total = listBox1.SelectedItem.ToString();
       dataGridView1.Rows.Add(new object[] {total});
       listbox1.ClearSelected();
   }
}

Other variant maybe you can use bindings and filter values if it`s checked. 如果检查了其他变体,则可以使用绑定和过滤器值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在列表框中获取选中的项目并打印到我的收据表格C#中 - How can I get my checked items in listbox and print to my receipt form C# 如何在 C# 中获得两列 winform 列表框? - How Can i get Two column winform listbox in C#? 如何使用Winforms C#获取用户在列表框中选择项目的顺序 - how do I get the order in which user selected Items in Listbox using Winforms c# 如何将选中列表框中的选中项目打印到 c# 中的 label? - how to print the checked items from the checked listbox to a label in c#? 如何在DataGridView C#中合并特定的列标题? - How can merge a particular column header in DataGridView C#? 如何获取列表框中所有选定项的数组? - How can I get an array of all selected items in a ListBox? 如何从 c# 中的 datagridview 通过列名从选定行中获取数据 - how do I get the data from selected row by its column name from datagridview in c# Windows 8 C# - 如何保留ListBox项? - Windows 8 C# - how to keep ListBox items? 当我在 C# 中有多个 datagridviews 时,如何获取当前选定的 datagridview 的名称? - How can I get the name of the current selected datagridview when I’ve multiple datagridviews in C#? 在C#Windows窗体的消息框中显示列表框的选定项目 - Displaying selected items of listbox into a message box in C# Windows Form
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM