473,386 Members | 1,827 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Works with table but not SP.

I want my datagrid to only select rows, not cells.

Here is my code so far. I think I'm really close. This code still selects
just cell, but I want the row selected, and if the user arrows up or down
then the next row or previous row is selected. No mouse is used in this
application.

private void frmDealerSearch_Load(object sender,
System.EventArgs e)
{
string sConnString = "Data
Source=db;Database=License;Integrated Security=False;User
ID=sa;password=password";
string sProc = "prGet_DealerInfo";

using (SqlConnection oCn = new
SqlConnection(sConnString))
{
using (SqlCommand oCmd = new
SqlCommand("Dealer_Info", oCn))
{
oCn.Open();
oCmd.CommandType =
CommandType.StoredProcedure;

oCmd.Parameters.Add("@sDealerNum",
SqlDbType.NChar, 6);

oCmd.Parameters["DEALER_NUMBER"].Value = "101043";

SqlDataAdapter oDa = new
SqlDataAdapter();

oDa.SelectCommand = oCmd;
DataSet ds=new DataSet();
oDa.Fill(ds);
DataGridTableStyle tableStyle = new
DataGridTableStyle();

int numCols =
ds.Tables[0].Columns.Count;
DataGridNoActiveCellColumn
aColumnTextColumn ;
for(int i = 0; i < numCols; ++i)
{
aColumnTextColumn = new
DataGridNoActiveCellColumn();
aColumnTextColumn.HeaderText
= ds.Tables[0].Columns[i].ColumnName;
aColumnTextColumn.MappingName = ds.Tables[0].Columns[i].ColumnName;

tableStyle.GridColumnStyles.Add(aColumnTextColumn) ;
}
dgDealerInfo.TableStyles.Clear();

dgDealerInfo.TableStyles.Add(tableStyle);
dgDealerInfo.DataSource =
ds.Tables[0];

}
}
}

}
public class DataGridNoActiveCellColumn : DataGridTextBoxColumn
{
private int SelectedRow = -1;
protected override void
Edit(System.Windows.Forms.CurrencyManager source, int rowNum,
System.Drawing.Rectangle bounds, bool readOnly,string instantText,bool
cellIsVisible)
{
//make sure previous selection is valid
if(SelectedRow > -1 && SelectedRow <
source.List.Count + 1)

this.DataGridTableStyle.DataGrid.UnSelect(Selected Row);
SelectedRow = rowNum;
this.DataGridTableStyle.DataGrid.Select(SelectedRo w);
}
}
Nov 17 '05 #1
5 1205
Hi Cadel,

Thanks for your post.

Based on my understanding, you want to select the entire row when user
click certain cell.

I think we can get this done with a much easier way: we can handle
DataGrid.MouseUp event, then do the hittest in that event and select the
entire row. For details, please refer to the link below:
"5.11 How can I select the entire row when the user clicks on a cell in the
row?"
http://www.syncfusion.com/FAQ/Window...44c.aspx#q689q

Hope this helps
=============================================
Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 17 '05 #2
As I stated before, " No mouse is used in this application." I was really
looking forward to a solution this morning, but now I'm angery that you gave
me a mouse click code, when I stated that no mouse is used in this
application.

This is a WinForm, and the mouse will not be used.

I've pasted my question in again, for you or anyone to provide me a solution
to set the datagrid to only select rows, not cells. I don't know how much
more to make that clear. But I'll try.

PROBLEM: when the datagrid first appears the focus is on the first cell,
(top left), if the user arrows down the cell below is then selected.

I WANT: the datagrid when it first appears to have the first row selected
AND WHEN THE USER CLICKS THE DOWN ARROW THE ROW BELOW IS SELECTED. If the
user then presses the up arrow the previous ROW is selected. When the user
presses the ENTER key the values from the selected row are stored in an array.

Here is the first post:

I want my datagrid to only select rows, not cells.

Here is my code so far. I think I'm really close. This code still selects
just cell, but I want the row selected, and if the user arrows up or down
then the next row or previous row is selected. No mouse is used in this
application.

private void frmDealerSearch_Load(object sender,
System.EventArgs e)
{
string sConnString = "Data
Source=db;Database=License;Integrated Security=False;User
ID=sa;password=password";
string sProc = "prGet_DealerInfo";

using (SqlConnection oCn = new
SqlConnection(sConnString))
{
using (SqlCommand oCmd = new
SqlCommand("Dealer_Info", oCn))
{
oCn.Open();
oCmd.CommandType =
CommandType.StoredProcedure;

oCmd.Parameters.Add("@sDealerNum",
SqlDbType.NChar, 6);

oCmd.Parameters["DEALER_NUMBER"].Value = "101043";

SqlDataAdapter oDa = new
SqlDataAdapter();

oDa.SelectCommand = oCmd;
DataSet ds=new DataSet();
oDa.Fill(ds);
DataGridTableStyle tableStyle = new
DataGridTableStyle();

int numCols =
ds.Tables[0].Columns.Count;
DataGridNoActiveCellColumn
aColumnTextColumn ;
for(int i = 0; i < numCols; ++i)
{
aColumnTextColumn = new
DataGridNoActiveCellColumn();
aColumnTextColumn.HeaderText
= ds.Tables[0].Columns[i].ColumnName;
aColumnTextColumn.MappingName = ds.Tables[0].Columns[i].ColumnName;

tableStyle.GridColumnStyles.Add(aColumnTextColumn) ;
}
dgDealerInfo.TableStyles.Clear();

dgDealerInfo.TableStyles.Add(tableStyle);
dgDealerInfo.DataSource =
ds.Tables[0];

}
}
}

}
public class DataGridNoActiveCellColumn : DataGridTextBoxColumn
{
private int SelectedRow = -1;
protected override void
Edit(System.Windows.Forms.CurrencyManager source, int rowNum,
System.Drawing.Rectangle bounds, bool readOnly,string instantText,bool
cellIsVisible)
{
//make sure previous selection is valid
if(SelectedRow > -1 && SelectedRow <
source.List.Count + 1)

this.DataGridTableStyle.DataGrid.UnSelect(Selected Row);
SelectedRow = rowNum;
this.DataGridTableStyle.DataGrid.Select(SelectedRo w);
}
}

""Jeffrey Tan[MSFT]"" wrote:
Hi Cadel,

Thanks for your post.

Based on my understanding, you want to select the entire row when user
click certain cell.

I think we can get this done with a much easier way: we can handle
DataGrid.MouseUp event, then do the hittest in that event and select the
entire row. For details, please refer to the link below:
"5.11 How can I select the entire row when the user clicks on a cell in the
row?"
http://www.syncfusion.com/FAQ/Window...44c.aspx#q689q

Hope this helps
=============================================
Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 17 '05 #3
Hi Cadel,

Sorry, it seems that I mislooked that "not using mouse" sentence.

If you do not want to use mouse, I think your code should meet your need. I
have tested your code snippet on my side. It works well: when the DataGrid
first appears, when DataGridNoActiveCellColumn.Edit method is called,
because we did not call the base version of Edit method, the first cell
will not become editable state, instead, our code will select the first
row. My test code listed below:

private void Form1_Load(object sender, System.EventArgs e)
{
DataTable dt=new DataTable();
dt.TableName="Test";
dt.Columns.Add(new DataColumn("column1", typeof(string)));
dt.Columns.Add(new DataColumn("column2", typeof(int)));

for(int i=0;i<5;i++)
{
DataRow dr=dt.NewRow();
dr["column1"]="item"+i.ToString();
dr["column2"]=i;
dt.Rows.Add(dr);
}

DataGridTableStyle dgts=new DataGridTableStyle();
dgts.MappingName="Test";

DataGridNoActiveCellColumn dgnacc=new DataGridNoActiveCellColumn();
dgnacc.MappingName="column1";
dgnacc.Width=100;
dgts.GridColumnStyles.Add(dgnacc);

dgnacc=new DataGridNoActiveCellColumn();
dgnacc.MappingName="column2";
dgts.GridColumnStyles.Add(dgnacc);

this.dataGrid1.TableStyles.Add(dgts);

this.dataGrid1.DataSource=dt;
}

public class DataGridNoActiveCellColumn : DataGridTextBoxColumn
{
private int SelectedRow = -1;
protected override void Edit(CurrencyManager source,
int rowNum, Rectangle bounds, bool readOnly, string instantText,
bool cellIsVisible)
{
//base.Edit (source, rowNum, bounds, readOnly, instantText,
cellIsVisible);
//this.DataGridTableStyle.DataGrid.Select(rowNum);
//make sure previous selection is valid
if(SelectedRow > -1 && SelectedRow <
source.List.Count + 1)

this.DataGridTableStyle.DataGrid.UnSelect(Selected Row);
SelectedRow = rowNum;
this.DataGridTableStyle.DataGrid.Select(SelectedRo w);

}
}
Does this code snippet work on your side? Do you forget the add
DataGridNoActiveCellColumn into DataGrid's column style collection? Do you
set the column style MappingName property correctly?

If you still have any concern, please feel free to tell me, thanks
================================================== =====
Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 17 '05 #4
Now I know what the problem is. I'm using a SP not a table. Your code
worked for me too, because you created a table. But if your code accessed a
SP, then it wouldn't work, like how my code is not working now.

I also tested creating a table (like you did) in my code and it worked, but
I want to use a SP.

So, now the question is, how do I get my code to work using a SP?
""Jeffrey Tan[MSFT]"" wrote:
Hi Cadel,

Sorry, it seems that I mislooked that "not using mouse" sentence.

If you do not want to use mouse, I think your code should meet your need. I
have tested your code snippet on my side. It works well: when the DataGrid
first appears, when DataGridNoActiveCellColumn.Edit method is called,
because we did not call the base version of Edit method, the first cell
will not become editable state, instead, our code will select the first
row. My test code listed below:

private void Form1_Load(object sender, System.EventArgs e)
{
DataTable dt=new DataTable();
dt.TableName="Test";
dt.Columns.Add(new DataColumn("column1", typeof(string)));
dt.Columns.Add(new DataColumn("column2", typeof(int)));

for(int i=0;i<5;i++)
{
DataRow dr=dt.NewRow();
dr["column1"]="item"+i.ToString();
dr["column2"]=i;
dt.Rows.Add(dr);
}

DataGridTableStyle dgts=new DataGridTableStyle();
dgts.MappingName="Test";

DataGridNoActiveCellColumn dgnacc=new DataGridNoActiveCellColumn();
dgnacc.MappingName="column1";
dgnacc.Width=100;
dgts.GridColumnStyles.Add(dgnacc);

dgnacc=new DataGridNoActiveCellColumn();
dgnacc.MappingName="column2";
dgts.GridColumnStyles.Add(dgnacc);

this.dataGrid1.TableStyles.Add(dgts);

this.dataGrid1.DataSource=dt;
}

public class DataGridNoActiveCellColumn : DataGridTextBoxColumn
{
private int SelectedRow = -1;
protected override void Edit(CurrencyManager source,
int rowNum, Rectangle bounds, bool readOnly, string instantText,
bool cellIsVisible)
{
//base.Edit (source, rowNum, bounds, readOnly, instantText,
cellIsVisible);
//this.DataGridTableStyle.DataGrid.Select(rowNum);
//make sure previous selection is valid
if(SelectedRow > -1 && SelectedRow <
source.List.Count + 1)

this.DataGridTableStyle.DataGrid.UnSelect(Selected Row);
SelectedRow = rowNum;
this.DataGridTableStyle.DataGrid.Select(SelectedRo w);

}
}
Does this code snippet work on your side? Do you forget the add
DataGridNoActiveCellColumn into DataGrid's column style collection? Do you
set the column style MappingName property correctly?

If you still have any concern, please feel free to tell me, thanks
================================================== =====
Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 17 '05 #5
Hi Cadel,

Thanks for your feedback.

After doing some research I found the problem in your code. No, the problem
has nothing to do with SP. Because after filling the DataSet/DataTable, the
Winform databinding will has nothing to do with where the data is from. The
DataBinding only concerns with the datasource.

Actually, your code is almost correct, except that it forgets to set the
DataGridTableStyle.MappingName property, so when DataGrid is populating the
data, it can not successfully map DataTable to the DataGridTableStyle. So
it will use its default DataGridTableStyle and DataGridColumnStyle etc...
It just ignores our DataGridTableStyle.

After adding this line of code, your code should work well:

dgDealerInfo.TableStyles.Clear();
tableStyle.MappingName=ds.Tables[0].TableName; //this
correctly sets the MappingName property
dgDealerInfo.TableStyles.Add(tableStyle);
dgDealerInfo.DataSource = ds.Tables[0];

Hope this helps.
=============================
Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 17 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Kim14 | last post by:
I have a table that works fine in IE, but doesn't work in Netscape or Firefox. It should automatically come up with numbers in some of the fields and depending what is entered, it should calculate...
1
by: Avi | last post by:
Hi All. This code works very fine in Firefox but not in I.E. Can anybody help me out? it gives ... "Unknown Runtime Error" in I.E. This code ... Stores N*2 Matrix at Client Side & provide the...
6
by: Giggle Girl | last post by:
I have an embedded style sheet that works perfect in IE6, and looks wrong in Firefox 1.7. Here is a link to an online sample: http://c.1asphost.com/giggy/tree02h/main/default.htm It works for...
8
by: Ian | last post by:
I have an Access 2000 database that checks once every 4 seconds to see if a text file exists, if it does then it opens the text file, reads an ID, opens a report based on that ID, then deletes the...
3
by: Mesut | last post by:
I have written a form in with radio buttons the name is set to orderby and the value is set to KundeVorName and the next value is KundeNachName and it goes so on. I wanna modify my query according...
4
by: clentoc | last post by:
I'm pretty new to javascript so this may well be a really basic error, but I've spent hours trying to fix it with no joy. I have written some code which looks in a CSV file, filters it depending...
2
by: namratha247 | last post by:
Hi, Can anybody please help me with this problem. In my application, I'm using Menus. and the CSS for the menu is as given below ccMenu.css /* Root = Horizontal, Secondary = Vertical */...
1
by: reemamg | last post by:
I've two frames in a page. On the left Frame i've buttons , if we click on button the particular pages will be loaded in the middle Frame. This code works perfectly in Firefox but not in IE ... ...
13
by: Stever1975 | last post by:
I'm working on something similiar to a shopping cart item page. There is a table of items. Each item has an image, a textbox for the qty and an image for the add button. When the add image is...
4
by: ArizonaJohn | last post by:
Hello, The code below works great. The user enters a name into an HTML form, the code looks up a table with that name, and then that table is displayed. I am trying to use pagination with it,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.