DataGridView choice of tetanus user



  • That's how you want to make a user. DataGrid(DataGridView) He chose the fields he needed to work. Data are developed dynamically as the names of the columns from the request. Used ODBC I'-I'm sorry. Conclusion DataGrid(DataGridView) It is done as follows:

    string sql="текст запроса";
    OdbcConnection conn = new OdbcConnection(connectionString);
    OdbcDataAdapter myda = new OdbcDataAdapter(hytechsql,conn);
    conn.Open();
    OdbcCommand cmd = new OdbcCommand(hytechsql,conn);
    myda.Fill(dt);
    dataGridView1.DataSource=dt;
    conn.Close();  
    

    Столбцы

    Overall, it was as follows:

    введите сюда описание изображения

    The buttons shall be operated as follows:

    / Replace the button +

            object item=listBox1.SelectedItem;
            int index=listBox1.SelectedIndex;
            int tempindex;
            if (index ==0||index<0)
            {
    
        }
        else
        {
            tempindex=index-1;
        object tempitem=listBox1.Items[tempindex];
        listBox1.Items.RemoveAt(index);
        listBox1.Items.Insert(index, tempitem);
        listBox1.Items.RemoveAt(tempindex);
        listBox1.Items.Insert(tempindex, item);
        listBox1.SelectedIndex = tempindex;
    

    button -

            object item=listBox1.SelectedItem;
    int index=listBox1.SelectedIndex;
    int tempindex;
    if (index == listBox1.Items.Count - 1||index<0)
    {

        }
        else {
            tempindex=index+1;
        object tempitem=listBox1.Items[tempindex];
        listBox1.Items.RemoveAt(index);
        listBox1.Items.Insert(index, tempitem);
        listBox1.Items.RemoveAt(tempindex);
        listBox1.Items.Insert(tempindex, item);
        listBox1.SelectedIndex = tempindex;
    



  • If you don't generate columns yourself, the element. DataGridView makes it automatic. After he did, the generated columns can be controlled.

    There will be an event at the end of the generation. DataBindingCompletewhich can be followed by the collection DataGridView.Columns and control the visibility of a separate column through the properties Visible♪ You can get the names of the columns for the list of displayed and hidden.

    Example https://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.databindingcomplete(v=vs.110).aspx

    private void dataGridView1_DataBindingComplete(object sender,
        DataGridViewBindingCompleteEventArgs e)
    {
        // Hide some of the columns.
        dataGridView1.Columns["EmployeeID"].Visible = false;
        dataGridView1.Columns["Address"].Visible = false;
        dataGridView1.Columns["TitleOfCourtesy"].Visible = false;
        dataGridView1.Columns["BirthDate"].Visible = false;
        dataGridView1.Columns["HireDate"].Visible = false;
        dataGridView1.Columns["PostalCode"].Visible = false;
        dataGridView1.Columns["Photo"].Visible = false;
        dataGridView1.Columns["Notes"].Visible = false;
        dataGridView1.Columns["ReportsTo"].Visible = false;
        dataGridView1.Columns["PhotoPath"].Visible = false;
    
    // Disable sorting for the DataGridView.
    foreach (DataGridViewColumn i in
        dataGridView1.Columns)
    {
        i.SortMode = DataGridViewColumnSortMode.NotSortable;
    }
    
    dataGridView1.AutoResizeColumns();
    

    }

    The principle of work is, it remains only to create the required form and to deflect the value of Visible and to change it when closed. For a list of values in shape, I think a simple ListBox will fit.




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2