VB6.0 datagrid顯示選中行的數(shù)據(jù)
VB6.0 datagrid顯示選中行的數(shù)據(jù)
在datagrid的單擊事件上添加文本框名稱.text=ado控件名稱.recordset(\”字段名稱\”)這樣就可以完成你的要求說明一下原因,因?yàn)楫?dāng)datagrid進(jìn)行單擊選擇的時候,當(dāng)前記錄就會移動到你單擊的數(shù)據(jù)行處,所以直接用文本框的text屬性直接顯示就可以的了,當(dāng)然,在顯示之前還要綁定數(shù)據(jù)控件,否則也不會顯示的!也有可能報錯綁定數(shù)據(jù)控件語句如下set文本框名稱.datasource=ADO控件名稱
如何vb 中用datagrid控件顯示數(shù)據(jù)庫中信息
首先需要有一個connection對象。用來連接數(shù)據(jù)庫可dim cnn as new adodb.connectiondim cnnstr=\”Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\” & App.Path & \”\\數(shù)據(jù)庫名.mdb;Persist Security Info=False\” cnn.CursorLocation = adUseClient cnn.open connstrdim rs as new adodb.recordsetdim sql=\”select * from tm\”rs.CursorLocation = adUseClientrs.open sql,cnn,1,3if not rs.eof thenset datagrid1.datasource=rsend if不懂的可以再向我提問。
VB中DataGrid1中的數(shù)據(jù)怎么才能顯示最近數(shù)據(jù)
設(shè)你的DataGrid1綁定的數(shù)據(jù)庫的表名為TBL1, 該表中存放名稱的字段名稱是\”YName\”, 在該表中增加一個字段, 字段名稱是\”ID\”,類型設(shè)為“自動編號”在Command1_Click() 事件中添加下面代碼:Dim CN As New ADODB.Connection Dim rs As New ADODB.RecordsetDim SQ As StringCN.CursorLocation = adUseClientCN.Open \”provider=microsoft.jet.oledb.4.0;data source=\” & App.Path & \”\\數(shù)據(jù)庫名.mdb\”SQ = \”select * from TBL1 order by ID desc where YName=\’ \” & Trim(Me.Text1.Text) & \” \’\”rs.Open SQ, CN, adOpenDynamic, adLockOptimisticSet Me.DataGrid1.DataSource = rs
datagrid 中如何顯示組合數(shù)據(jù)
如此,你的意思應(yīng)該是分組的意思了:如下
xaml
<sdk:DataGrid?AutoGenerateColumns=\”False\”?Height=\”300\”?HorizontalAlignment=\”Left\”?Name=\”dataGrid1\”?VerticalAlignment=\”Top\”?Width=\”400\”?>
<sdk:DataGrid.Columns>
<sdk:DataGridCheckBoxColumn?Binding=\”{Binding?IsMale}\”></sdk:DataGridCheckBoxColumn>
<sdk:DataGridTextColumn?Binding=\”{Binding?Age百科}\”></sdk:DataGridTextColumn>
<sdk:DataGridTextColumn?Binding=\”{Binding?Name}\”></sdk:DataGridTextColumn>
</sdk:DataGrid.Columns>
</sdk:DataGrid>
codebehind如下:
public?List<Teacher>?lst?=?new?List<Teacher>()?{?new?Teacher(\”zsl\”,?20,?true),?new?Teacher(\”zsl\”,?40,?true),?new?Teacher(\”zsl\”,?20,?false),?new?Teacher(\”zsl1\”,?100,?true),?new?Teacher(\”kkk\”,?200,?true),?new?Teacher(\”kkk\”,?20,?false)?};
public?MainPage()
{
InitializeComponent();
PagedCollectionView?pcv?=?new?PagedCollectionView(lst);
pcv.GroupDescriptions.Add(new?PropertyGroupDescription(\”IsMale\”));
pcv.GroupDescriptions.Add(new?PropertyGroupDescription(\”Age\”));
pcv.GroupDescriptions.Add(new?PropertyGroupDescription(\”Name\”));
this.dataGrid1.ItemsSource?=?pcv;
}
}
public?class?Teacher
{
private?string?_name;
public?string?Name
{
get
{
return?_name;
}
}
public?int?Age
{
get
{
return?_age;
}
}
private?int?_age;
private?bool?_isMale;
public?bool?IsMale
{
get
{
return?_isMale;
}
}
public?Teacher(string?name,?int?age,?bool?isMale)
{
_name?=?name;
_age?=?age;
_isMale?=?isMale;
}
結(jié)果如下
如何實(shí)現(xiàn)VB中用DataGrid控件顯示數(shù)據(jù)?
Dim
C# dataGridView 顯示特定的數(shù)據(jù)
既然**一句提示得到了四條數(shù)據(jù),那說明從數(shù)據(jù)庫中獲取數(shù)據(jù)應(yīng)該沒問題,是數(shù)據(jù)綁定有錯誤。很顯然datagridview1.datasource=dt;這句只是為datagridview控件添加了數(shù)據(jù)源,但未進(jìn)行數(shù)據(jù)綁定,只要在datagridview1.datasource=dt;后加上datagridview1.databind();就可以了。