vb代码 For i As Integer = 0 To GridView1.RowCount - 1 ListBox1.Items.Add(GridView1.GetRowCellValue(i, GridView1.Columns.Item(0))) Next
这么简单啊,谢谢啊 能不能把这个添加到GridControl的双击事件里啊,比如双击某一行,使双击行的所在列的数据添加到listbox中(c#语言),每次添加一个,以下是我搞的一部分程序,请指点 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Data.OracleClient;namespace WindowsApplication1 { public partial class Form1 : Form { int indexofsource;//拖动的起始索引 int indexoftarget; //拖动的结束索引 public Form1() { InitializeComponent(); } private void Updata() { OracleConnection conn = new OracleConnection(Properties.Settings.Default.ConnectionString1); OracleCommand cmd = new OracleCommand(); cmd.Connection = conn; cmd.CommandText = "SELECT NAME FROM TEST1"; OracleDataAdapter adapter = new OracleDataAdapter(); adapter.SelectCommand = cmd; DataTable dt = new DataTable(); tEST1BindingSource.DataSource = dt; adapter.Fill(dt);
是不是这样:
ListBoxRooms.Items.Add(GridView1.GetFocusedRowCellValue(GridView1.FocusedColumn))
For i As Integer = 0 To GridView1.RowCount - 1
ListBox1.Items.Add(GridView1.GetRowCellValue(i, GridView1.Columns.Item(0)))
Next
能不能把这个添加到GridControl的双击事件里啊,比如双击某一行,使双击行的所在列的数据添加到listbox中(c#语言),每次添加一个,以下是我搞的一部分程序,请指点
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.OracleClient;namespace WindowsApplication1
{
public partial class Form1 : Form
{
int indexofsource;//拖动的起始索引
int indexoftarget; //拖动的结束索引
public Form1()
{
InitializeComponent();
} private void Updata()
{
OracleConnection conn = new OracleConnection(Properties.Settings.Default.ConnectionString1);
OracleCommand cmd = new OracleCommand();
cmd.Connection = conn;
cmd.CommandText = "SELECT NAME FROM TEST1";
OracleDataAdapter adapter = new OracleDataAdapter();
adapter.SelectCommand = cmd;
DataTable dt = new DataTable();
tEST1BindingSource.DataSource = dt;
adapter.Fill(dt);
}
private void button1_Click(object sender, EventArgs e)
{
Updata();
}
private void button2_Click(object sender, EventArgs e)
{
listBox1.Items.Add(gridView1.GetFocusedRowCellValue(gridView1.FocusedColumn));
} private void listBox1_MouseDown(object sender, MouseEventArgs e)
{
indexofsource = ((ListBox)sender).IndexFromPoint(e.X, e.Y);
if (indexofsource != ListBox.NoMatches)
{
((ListBox)sender).DoDragDrop(((ListBox)sender).Items[indexofsource].ToString(), DragDropEffects.All);
}
} private void listBox1_DragDrop(object sender, DragEventArgs e)
{
ListBox listbox = (ListBox)sender;
indexoftarget = listbox.IndexFromPoint(listbox.PointToClient(new Point(e.X, e.Y)));
if (indexoftarget != ListBox.NoMatches)
{
string temp = listbox.Items[indexoftarget].ToString();
listbox.Items[indexoftarget] = listbox.Items[indexofsource];
listbox.Items[indexofsource] = temp;
listbox.SelectedIndex = indexoftarget;
} } private void listBox1_DragOver(object sender, DragEventArgs e)
{ //拖动源和放置的目的地一定是一个ListBox
if (e.Data.GetDataPresent(typeof(System.String)) && ((ListBox)sender).Equals(listBox1))
{
e.Effect = DragDropEffects.Move;
}
else
e.Effect = DragDropEffects.None; }
}
}